Jump to content
xisto Community
Sign in to follow this  
r0b

Hiding <Br> Tags In Textarea

Recommended Posts

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 by r0b (see edit history)

Share this post


Link to post
Share on other sites

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

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 by dab (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.