Hi all, I have a little script that replace some text, that come from a xml file, this is an example:
<b>Hello world,</b>
<include file="dynamiccontent.php" />
<img src="world.png" />
a lot of <i>stuff</i>
Obviosly the string is much more longer, but I would like to replace the <include
file="*" />
with the content of the script in the filename, at time I use an explode that find
<include file="
but I think there is a better method to solve it. This is my 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;
}
I'm sure that a regexp done well can be a good replacement.