1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| function strlastpos($haystack, $needle) {
return strlen($haystack) - strlen($needle) - strpos(strrev($haystack), strrev($needle));
}
function strinsert($str, $pos, $substr) {
$part1 = substr($str, 0, -$pos);
$part2 = substr($str, -$pos);
return $part1.$substr.$part2;
}
$new_article = '<article>
<headline></headline>
<date></date>
<copy_intro><![CDATA[<p> </p>]]></copy_intro>
<image_thumb></image_thumb>
<article_link></article_link>
</article>';
$end_article = '</article>';
$pos = strlastpos($xml, $end_article);
$xml = strinsert($xml, $pos + strlen($end_article), $new_article); |
Partager