I'm trying to write a function that will replace any occurrence of numbers that start and ends with PID. I think the problem is in the regex but I can't figure it out. The code is below. I also tried just (.) instead of (.*) - no difference. I know I will have to loop through the matches array to get all occurrences but I wanted to get the basic code working first. Would someone please point out the problem?
function DoLinks($matches) {
return ($matches[0]='<a href="someplace.com">Some place</a>');
}
function Buildinks($text) {
preg_replace_callback(
"/PID(.*)PID/",
"DoLinks",
$text);
return $text;
}
$text = "hello PID(199)PID";
$text = Buildinks($text);
echo $text;