You are here: Re: Multi - level parsing « PHP Language « IT news, forums, messages
Re: Multi - level parsing

Posted by Michael on 02/04/07 15:36

I found this solution:

function ReplaceTags($input) {
$offset = 0;
$regex = '#\[(.*?)((?:\|.*?)*)(?:/|\](.*?)\[/\1)\]#s';
// Find a matching tag pair, using offset $offset
while (preg_match($regex, $input, $matches, PREG_OFFSET_CAPTURE,
$offset)) {
// If it contains another opening tag, skip over this and let
// the next loop execution handle it
if (preg_match('#\[[^/](.*?)\]#s', $matches[3][0], $m))
$offset = $matches[0][1] + 1;
else
{
// If it's not an opening tag, we can safely parse it
// Replace the tag with it's processed value and start from the beginning
$input = substr_replace($input, ParseTag(array($matches[0][0],
$matches[1][0], $matches[2][0], $matches[3][0])), $matches[0][1],
strlen($matches[0][0]));
$offset = 0;
}
}
return $input;
}

Don't mind the ParseTag call, it's the old version expecting an array
directly from the preg_match. Doesn't seem to be too slow - I expect to be
parsing mostly top-level and singly nested tags anyway.

Kind regards

Michael.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация