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
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
Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.