Trying to match a string like ^grape-ape
to run a search using Leafly API. I am just no good at regex, my dyslexia looses me on the patterns.
Any ideas why it doesn't seem to be matching/replacing?
/*********************/
/* Tag Search Test */
/*********************/
$str = 'I really love that ^blue-dream and ^grape-ape';
preg_match('/^\^([a-z0-9\-])/i', $str, $match);
if (!(empty($match)) && $match != false) {
$slugs = $match;
if(!(is_array($slugs))) {
$strain = exec('curl -v -H "app_id:*******************" -H "app_key:*******************" -X GET "http://data.leafly.com/strains/'.$slugs.'"');
if (is_array(json_decode($strain))) {
$str = preg_replace('/^\^('.preg_quote($slugs).')/i', '<span title="'.$strain['descriptionPlain'].'">'.$strain['name'].'</span>', $str);
}
} else {
foreach($slugs as $slug) {
$strain = exec('curl -v -H "app_id:*******************" -H "app_key:*******************" -X GET "http://data.leafly.com/strains/'.$slug.'"');
if (is_array(json_decode($strain))) {
$str = preg_replace('/^\^('.preg_quote($slug).')/i', '<span title="'.$strain['descriptionPlain'].'">'.$strain['name'].'</span>', $str);
}
}
}
}
echo '<pre>';
print_r($str);
echo '</pre>';
/*********************/
/* Reference Test */
/*********************/
$strain = exec('curl -v -H "app_id:*******************" -H "app_key:*******************" -X GET "http://data.leafly.com/strains/grape-ape"');
echo '<pre>';
print_r(json_decode($strain));
echo '</pre>';