str_replace() problems actually *_replace() problems to be more accurate
| From: | Thomas Bolioli | Date: | Mon, 16 Jun 2003 18:49:14 +0000 |
| Subject: | str_replace() problems actually *_replace() problems to be more accurate | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-151704@lists.php.net to get a copy of this message | ||
I am a perl/java/c++ programmer who is doing something in php and have run accross something I am stumped with. I am trying to replace carriage returns with <br> or <p> tags (p's in groups of two and br's for any unmatched cr's). I have tried all of the *_replace() functions including string_*, ereg_* and preg_*. None have worked the way they seem to should. Note, I am a perl programmer and preg_replace() did not work while a test perl script did. I have tried multiple forms of patterns from "\r\n" to "\n" to "\r" to "/\r?\n/ei" (in the *reg_* functions). I even took code verbatim from examples in the docs to no avail. I have included the entire block of code (and mysql_dump output) since there is something I have apparently not done right and it may not be in the pattern matches.
Thanks in advance,
Tom
*The offending code:*
}elseif($_REQUEST['add']){
$desc = $_REQUEST['description'];
str_replace("\r\n\r\n", "<p>", $desc);
str_replace("\r\n", "<br>", $desc);
$result = mysql_query('INSERT INTO hr_listings (title,description,location,end_date,posting_date) VALUES("'.$_REQUEST['title'].'","'.$desc.'","'.$_REQUEST['location'].'","'.$_REQUEST['end_date'].'", NOW())',$db)
or trigger_error("MySQL error nr ".mysql_errno().": ".mysql_error());
*Output of mysql_dump showing the \r\n's going in*
INSERT INTO hr_listings VALUES (15,'test',5,'2003-06-16','2003-09-11',NULL,'This
is one line\r\nThis is the next\r\n\r\nThis is another paragraph\r\n\r\n');
INSERT INTO hr_listings VALUES (16,'test2',1,'2003-06-16','2004-09-11',NULL,'Thi
s is one line\r\nThis is the next\r\n\r\nThis is another paragraph\r\n\r\n');