Ben bir xml dosyası gelen bazı metin yerine küçük bir komut dosyası var, bu bir örnektir:
<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;
}
Ben iyi yapılan bir sıradanifade iyi bir yedek olabilir emin değilim.