take a look at the comments for the nl2br() functions, many nice examples for 
problems simular to this:

http://no2.php.net/manual/en/function.nl2br.php



On Mon, 16 Jun 2003 20:49:14 +0200, Thomas Bolioli wrote
(in message <[EMAIL PROTECTED]>):

> 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');
> 
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to