I want to anchor the sentence words that are in the array.
<?php
$names = array('sara', 'max', 'alex');
foreach ($names as $dt) {
$name = '@' . $dt;
$text = preg_replace('/(' . $name . '\s)/', ' <a href=' . $dt . '>\1</a> ', $text);
}
echo $text;
?>
when my sentence like this it works well.
$text = "@sara @alex @max";
but when my sentence like this
$text = "hello @sara hello @max hello @alex";
it doesn't work well.