add anchor tag if content have some particular tags

51 views Asked by At

I'm trying to add anchor tag in few texts if article page returns some specific tags.

For example I have this article page.

some dummy paragraph here India Russia Serbia paragraph content

Tags of this pages are India, Serbia

So, I want to add anchor tag to India and Serbia in this content (

some dummy paragraph here India Russia Serbia paragraph content

). I have tried this below code, but it add the anchor tag on last tag (Serbia)

$tags = array();
$tag_row = array();
foreach($article_tags as $tag)
{   
    $tag_row['text'] = $tag['tag_name'];
    $tag_row['url'] =  asort_get_url(ARTICLE_BASE_URL,$tag['tag_url']);
    array_push($tags,$tag_row);
    
    echo $tag_row["text"]; // but this line returns IndiaSerbia
    // detect tag links in content and add anchor tag   
    echo $article_content_with_tags = preg_replace("/(".$tag_row['text'].")/i","<a href=".ARTICLE_BASE_URL."/".$tag_row['url']."><b>$1</b></a>",$article_content);
}
0

There are 0 answers