i want to search my string and replace some words by link to some page.
but i have problem with similar words like "Help" and "Help Me".
i want to link "Help Me" not "Help".
this is my code:
$text="Please Help Me Fix This Issue!";
$AllTags=[];
$AllTags[]='Help';
$AllTags[]='Help Me';
$tmp = array();
foreach($AllTags as $term){
$tmp[] = "/($term)/i";
}
echo preg_replace($tmp, '<a href="$0">$0</a>', $text);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…