I am getting a string in my PHP output with lots of n
characters which I would like to convert into <p>
to get a new line characters in html outpot.
I have tried following:
JavaScript
x
strtr($myString, "n", "<p>");
string_replace ("n", "<p>", $myString);
Both of these doesn’t seems to work. Any ideas what’s wrong in the syntax?
Advertisement
Answer
Try this:
PHP:
JavaScript
<?php
$myString = 'HellonWorld';
echo '<p>'. implode('</p><p>', explode('n', $myString)) .'</p>';
?>
Output:
JavaScript
<p>Hello</p><p>World</p>