I am learning the language php. I have two functions and I want to connect these two and show them in one output php.
<?php
function link_follow($id)
{
$title = '';
$slug = '';
if ( $id == 44 ){
$title = 'Follow';
$slug = 'link/'.$id;
$read = '<a href="follow/'. $slug .'">'. $title .' : '.$id.'</a>';
return $read;
}
return '-';
}
function content_html($string)
{
$string = preg_replace('/\[FOLLOW_LINK id=(\d+)\]/i', link_follow('$1') , $string);
return $string;
}
$content= 'it is a test. Link: [FOLLOW_LINK id=44]';
echo content_html($content);
?>
out (html);
it is a test. Link: -
But i want to show the output (html) as below:
it is a test. Link: <a href="follow/link/44">Follow : 44</a>
It should show this code <a href="follow/link/44">Follow : 44</a>.
I think this code preg_replace does not work.
Because the string
'$1'you passed to the function has no special meaning, you should use thepreg_replace_callbackfunction: