Preg_replace
7 posts by 3 authors in: Forums > CMS Builder
Last Post: September 24, 2013 (RSS)
I am trying to replace </p> with <br /> in specific content. I am using the following code :
<?php echo preg_replace('</p>', '<br />', $articlesRecord['content']); ?>
It works in that is puts the correct spacing in but adds the < > into the content. See attached screenshot.
Can you help me figure what I am missing or doing wrong?
Thanks!
April
My suggestion ;-)
<?php echo string_ireplace( '</p>', '<br />', $articlesRecord['content']); ?>
Peace and Long Life
That should work you need to show a before and after to give me a little bit if a hint.
Peace and Long Life
Here is the error I get:
Fatal error: Call to undefined function string_ireplace() in C:\inetpub\carolinaparent\newarticlemain.php on line 234
My page is attached.
Thanks so much!
By Jason - September 24, 2013
Hi,
The issue is just a typo in the code. The function name is str_ireplace(). The only issue I can see with this, is that it will leave a lot of open <p> tags in your HTML, to strip those out as well, give this a try:
<p><?php echo str_replace("</p>", "<br/>", str_replace("<p>", "", $articlesRecord['content']));?></p>
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/