I want the word between characters
'@' ,'_'
Change to
<a href="$word">$word</a>
Example :
@Ali_ is a good boy, I and @Jan_ love him
change to
<a href="/Profile/Ali">Ali</a> is a good boy, I and <a href="/Profile/Jan"> Jan</a> love him
Thanks for your response
$string = 'ae @ali er @hassan sss';
$string = preg_replace("/@(.+?) /is", "<a href='Profile/$1'>$1</a>", $string);
echo($string);
Tried and tested:
function replaceString($content = '') {
preg_match_all('/@(.*?)_/', $content, $matches);
if(is_array($matches[0])) {
foreach($matches[0] as $key => $match) {
$new = $match;
$new = str_replace('@', '', $new);
$new = str_replace('_', '', $new);
$new = '<a href="/Profile/' . $new . '">' . $new . '</a>';
$content = str_replace($match, $new, $content);
}
}
return $content;
}
The output of the following:
$content = '@name1_ and this other @name2_';
$content = replaceString($content);
echo $content;
Will be:
<a href="/Profile/name1">name1</a> and this other <a href="/Profile/name2">name2</a>