r0b 0 Report post Posted September 11, 2010 (edited) Hello everyone, my name is Rob. (obvious huh?) Brief description: This project saves all the content to .txt files, you can edit them with a password that is saved in a .php file. You can edit the content with simply clicking on it (edit-in-place Ajax technology). I'm stuck at 99% of this flat-file (no database - writes to text files) CMS. Here's how it looks like. (password is admin) My problem are <br> tags. I need to make them invisible, to when the user hits enter (new line), it would make the new line, but the <br> tag would be hidden. So far I've tried: $content=nl2br($content);and$content = str_replace("<br>", "\n", $content); and also the code below for outputting the content, but that also didn't help. <?php echo "<pre>"; echo $file1; echo "</pre>";?> I'm really stuck in confusion and don't know what do to next? Edited September 11, 2010 by r0b (see edit history) Share this post Link to post Share on other sites
truefusion 3 Report post Posted September 13, 2010 I would assume the reason why your str_replace code does not work is because it doesn't find "<br>" and that the content of the text file actually contains "<br/>". By default the second parameter of nl2br is always "true" unless otherwise specified. This tells PHP to translate new lines to "<br/>" since it is XHTML compatible. You are better off using something like preg_replace to search for both <br> and <br/> in the content of the text file. Share this post Link to post Share on other sites
dab 0 Report post Posted September 19, 2010 (edited) As mentioned above, regex is where its at. echo preg_replace( '#<br[\s]{0,}[/]{0,1}>#', "\n", $content ); This regex will match <br> <br > <br/> <br />Examples here:[15:26:26] <+dab> <> echo preg_replace( '#<br[\s]{0,}[/]{1}>#', "\n", "Hello<br />World" );[15:26:26] <%DeBot> Hello[15:26:26] <%DeBot> World[15:26:45] <+dab> <> echo preg_replace( '#<br[\s]{0,}[/]{0,1}>#', "\n", "Hello<br >World" );[15:26:45] <%DeBot> Hello[15:26:45] <%DeBot> World Edited September 19, 2010 by dab (see edit history) Share this post Link to post Share on other sites