I have a normal paragraph like this:
<p>Hey there, I'm a normal paragraph. generated by a WordPress blog</p>
And I want to change the:
<p> with <h2> and </p> with </h2>
I used str_replace();
$paragraph = array("<p>", "</p>");
$heading2 = array("<h2>","</h2>");
$first_sentence = str_replace($paragraph, $heading2, $first_sentence);
And it should work, but I get this:
<h2>Hey there, I'm a normal paragraph. generated by a WordPress blog<p>/p></p>
Any ideas why?
You can use Regex for this kind of task:
([^<]+)means: catch all chars, until<occurs.Here you can see it working: http://codepad.viper-7.com/FW1vm5
But if it gets more complex you should use other techniques (like a DOM parser)