Jump to content

Preg Replace Callback Help


iwpg

Recommended Posts

This is what I have originally, any help to get this translated to preg_replace_callback will be so much appreciated!

function addtemplateslashes($template)
{
	return "?".">".$template."<?php";
}
$template = preg_replace("/\?".">(\r*\n*.*)(<\?php|<\?)/esiU","addtemplateslashes('\\1')",$template);

And this is what I have so far with no luck.

	if (!function_exists('parseTagsRecursive')) {
		function parseTagsRecursive($template) 
		{
			
			$regex = '#\/\?".">(\r*\n*.*)(<\?php|<\?)#';

			if (is_array($template)) {
				$template = $template[1];
			}

			return preg_replace_callback($regex, 'parseTagsRecursive', $template);
		}
	}
$template = parseTagsRecursive($template);
Link to comment
https://forums.phpfreaks.com/topic/284259-preg-replace-callback-help/
Share on other sites

Heck, you don't even need callbacks for it at all. And don't worry about the ?>s: PHP's smart enough to know not to stop processing in the middle of a string.

 

And the only difference between the search and replacement string is using the long open tags, so don't bother searching for the long ones. To avoid matching [ic]<?php[/i], use a negative assertion: "there must not be a 'php' at this point".

$template = preg_replace("/\?>(\r*\n*.*)$1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.