I have a text file that looks like this: It is like this and this and like this lalala text Well I am using file_get_contents(); and then displaying it as HTML. I want to use str_replace() to replace the new lines. What would I replace. I tried /n but it didn't work. What should I try replacing?
Don't you mean \n? Use this: <?php $content = <<<CONTENT It is like this and this and like this lalala text CONTENT; $content = str_replace("\n","", $content); highlight_string($content); ?> PHP:
It doesn't. Can you show your code? $content = "Hello This is a test to see if n and r get removed from a file using regex"; $result = preg_replace('%[\r\n]+%', '', $content); echo $result; PHP: That code shows perfectly
Hmm, so did mine -> http://forums.digitalpoint.com/showpost.php?p=13351017&postcount=2 I tested, so would help if op displayed his code.
@$note_contents = preg_replace('%[\r\n]+%', '<br />', $note_contents); echo '<div align="center"><b>' . $note_title . '</b><br />By: ' . $note_author . '</div><br /><br />'; echo $note_contents; Code (markup): It replaces it with a new line new lines but also n's and r's
If you just want to replace new lines with br why not just use $note_contents = nl2br($notecontents); PHP: