hi, i was making a script and i wanted to insert some text to mysql database and use "\n" for line breaks. means that i want a coding to turn "\n" into <br /> tag can anyone help? Thanks.
After you have retreived the content from the database, you can use the nl2br function which will do it for you. http://php.net/manual/en/function.nl2br.php
One of the guys that commented on that php.net page created a function to do what you want. function mynl2br($text) { return strtr($text, array("\r\n" => '<br />', "\r" => '<br />', "\n" => '<br />')); } PHP:
it works you just need to add more replacing patterns. $arr = array("<br>","<BR>","<br/>","<br />", "<BR/>"); str_replace($arr, "\n", "here I am<br> this is meeee<br>"); PHP: it works fine with me..
i think this code solve your problems str_replace("<br />", "\n", "here I am<br /> this is meeee<br />");
xenon i need to trun \n to <br /> not <br /> to \n. well i think if itell the coding help will be easier. str_replace('\n','<br />',$r2[news]); echo "<hr /><b>".$r2[title]."</b><br /><br />".$r2[news]."<br /><br /><b>By Admin</b> on <b> ".$r2[date]."</b><hr />"; PHP: i will now try to echo news within quotes
Does'nt work in all cases, furthermore I beleive only supports the \n newline character? and not the other OS based chars?