 |
 |
Easy way to remove a extra <br> tag with php?
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Howdy, I've got this bug, which I've been spending far too long trying to solve, time to call in the cavalry...
I'm using...
$foo=ereg_replace("<br>",chr(13),$foo);
and....
$foo=ereg_replace(chr(13),"<br>",$foo);
...to register the enter key as a <br> and vica versa when throwing data in and out of a mysql database using an input / edit form.
Problem is that when someone edits everything but the first line, a <br> (which is not seen by that someone) remains.
Anyone know of a quick fix?
|
|
|
| |
|
|
|
 |
|
 |
|
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status:
Offline
|
|
Originally posted by skalie:
Howdy, I've got this bug, which I've been spending far too long trying to solve, time to call in the cavalry...
I'm using...
$foo=ereg_replace("<br>",chr(13),$foo);
and....
$foo=ereg_replace(chr(13),"<br>",$foo);
...to register the enter key as a <br> and vica versa when throwing data in and out of a mysql database using an input / edit form.
Problem is that when someone edits everything but the first line, a <br> (which is not seen by that someone) remains.
Anyone know of a quick fix?
my brain doesn't seem to be functioning properly today, so i'm not sure if i read this right, but, do you need something like this?
ereg_replace("\r\n", "<br />", $foo);
|
|
"Have sharp knives. Be creative. Cook to music" ~ maxelson
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Originally posted by philzilla:
my brain doesn't seem to be functioning properly today, so i'm not sure if i read this right, but, do you need something like this?
ereg_replace("\r\n", "<br />", $foo);
Not quite, well it doesn't seem to do more than the
$foo=ereg_replace(chr(13),"<br>",$foo);
version did.
It's quite a difficult one to describe.....say if I didn't use the ereg_replace the textfield to be editted would appear in the form as
but after using the ereg_replace the textfield to be editted appears as
removing the second "bla" leaves a <br> after the first "bla" in the code
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
This seems to work fine for me:
[php]
<?php
$str = "a <br><br> b <br><br> c";
print str_replace("<br>", "\r\n", $str);
?>
[/php]
It prints:
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Do you mean you get unnecessary line spaces at the start or end or your string?
Simple:-
$foo=ereg_replace("<br>",chr(13),trim($foo));
or vice versa... trim() gets rid of linefeeds, tabs and other whitespace from both ends of the string.
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Originally posted by Simon Mundy:
Do you mean you get unnecessary line spaces at the start or end or your string?
Simple:-
$foo=ereg_replace("<br>",chr(13),trim($foo));
or vice versa... trim() gets rid of linefeeds, tabs and other whitespace from both ends of the string.
Simon it's 5.30 am and you just made my day, thanks a million.
I had tried adding $foo=rtrim($foo); after the ereg_replace statement, but now it's all coming a little clearer.
I knew there had to be an easy method.
Sometimes I think I'm far too much of a perfectionist to be a programmmer, spending hours on tiny potential problems while the real work lags way behind.
|
|
|
| |
|
|
|
 |
|
 |
|
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status:
Offline
|
|
Originally posted by skalie:
spending hours on tiny potential problems while the real work lags way behind.
ugh, tell me about it
|
|
"Have sharp knives. Be creative. Cook to music" ~ maxelson
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by philzilla:
ugh, tell me about it
I get distracted with anyone else's problems but my own. Like these forums, for example. Keeps me interested, but sure makes my deadlines stretchy... 
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|