I have a content like below.
I want the <pre></pre>
to be converted to <p> </p>
. But i'm not able achieve it. Below is an example
$content = "<pre>This is a pre text I want to convert it to paragraphs ";
print_r(str_replace(array('<pre>', '</pre>', ' '),array('<p>', '</p>', '<br/>'),htmlspecialchars($content)));
But i get the output as it is. Can someone help me resolve. Thanks in advance
You are changing $content
before replacing the string.
$content = "<pre>This is a pre text I want to convert it to paragraphs ";
print_r(htmlspecialchars($content));
// returns <pre>This is a pre text &#13; I want to convert it to paragraphs
None of which matches your str_replace
Remove the htmlspecialchars()
and you will get the output you wanted.
$content = "<pre>This is a pre text I want to convert it to paragraphs ";
print_r(str_replace(array('<pre>', '</pre>', ' '),array('<p>', '</p>', '<br/>'),$content));
//returns <p>This is a pre text <br/> I want to convert it to paragraphs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With