RegExp replace a specific XML/HTML TAG in PHP

DaRkLiFe

New Member
I have a little script that replace some text, that come from a xml file, this is an example:\[code\]<b>Hello world,</b><include file="dynamiccontent.php" /><img src="http://stackoverflow.com/questions/3810873/world.png" />a lot of <i>stuff</i>\[/code\]Obviosly the string is much more longer, but I would like to replace the \[code\]<include file="*" />\[/code\] with the content of the script in the filename, at time I use an explode that find\[code\]<include file="\[/code\]but I think there is a better method to solve it.This is my code:\[code\]$arrContent = explode("<include ", $this->objContent->content); foreach ($contenuto as $piece) { // Parsing array to find the include $startPosInclude = stripos($piece, "file=\""); // Taking position of string file=" if ($startPosInclude !== false) { // There is one $endPosInclude = stripos($piece, "\"", 6); $file = substr($piece, $startPosInclude+6, $endPosInclude-6); $include_file = $file; require ($include_file); // including file $piece = substr($piece, $endPosInclude+6); } echo $piece; }\[/code\]I'm sure that a regexp done well can be a good replacement.
 
Back
Top