Tried various different ways but it always end up failing, it either miss some tags or it creates a link inside another link I'm not even sure if i'm understanding it correctly, my code is a mess...
$tags = array("test","testing");
$text = "I'm testing with this test zz ...";
foreach ( $tags as $tag ) {
$array_text_only = preg_split('#<\w+[^>]*>|</\w+>#', $text);
foreach ( $array_text_only as $text_only ) {
$text_only_replace = preg_replace(
'#\b('.$tag.'\pL*)#ui',
"<a href=''>$1</a>",
$text_only,
1
);
$text = str_replace($text_only,$text_only_replace,$text);
}
}
What am I doing wrong?