Forum Moderators: coopster
$stringA = " ...<a href=aaa.html>Eat at joes</a>... ";
$stringB = "This is a paragraph of longer text. <p> There is more. <p> It continues. <p> And it ends <p>.";
$output = "This is a paragraph of longer text. <p> There is more. <p> ...<a href=aaa.html>Eat at joes</a>... It continues. <p> And it ends <p>."; four paragraphs, delineated by eight <p> marks
$stringA = " ...<a href=aaa.html>Eat at joes</a>... ";
$stringB = "This is a paragraph of longer text. <p> There is more. <p> It continues. <p> And it ends <p>.";
$totalNumber = magicalFunction($stringB); \\ result is "4" let's say...
\\ Something magical splits the string at the mid-paragraph-number point...
$newString = ($firstHalfOfString . $stringA . $secondHalfOfString); (<p>(?:[^<>]*</?[a-oq-z][^>]*>)*[^<>]*</p>\n*){X}<p>) $stringA = "<a href=aaa.html>Eat at joes</a>";
$stringB = "<p>This is a paragraph of longer text. <p> There is more. <p> It continues. <p> And it ends.";
// count paragraphs
$nParagraphs = substr_count($stringB, '<p>');
// find the middle (round up)
$nHalfParagraphs = ceil($nParagraphs / 2);
$newStringB = preg_replace('/((?:<p>.*?){' . $nHalfParagraphs . '})(?=<p>)/', '$1' . $stringA, $stringB);
echo $newStringB;