I am trying to use preg_replace in a foreach loop.
I need to replace all keywords wrapped between '%' and use the back reference.
For example, in my text I have few keywords like %author% %title% I need to replace the keywords so they look like $items->author and $items->title
I have tried with the following code but it just displays $items->author as a text and not retrieving the info from the array.
foreach ($xml->book as $items) {
echo preg_replace('/\%(.*?)\%/e', '$items->${1}', $content);
}
Any idea for this ?
$items->{$1}?echo preg_replace('/\%(.*?)\%/e', $items->${1}, $content);