Re: Simple String Replace Question

From: Date: Mon, 26 Feb 2001 04:34:23 +0000
Subject: Re: Simple String Replace Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41645@lists.php.net to get a copy of this message
From: "Jeff Oien" <jeff@webdesigns1.com> > Ok now I'm really being a pest. Your code works on your > example but not on mine. I can't figure out why. But I really > appreciate the help so far from Chris and Simon so thanks. > > Here is my example and what happens when I use your > code. I tried it by pasting text into a textarea part of a > form and also just having it in a plain text file (Windows system). > (I just tried creating a file on Unix also, same result.) > Removes the line breaks but also the multiples for paragraphs. > This isn't very important, more of a curiosity. I just tried with your text and it reformats it correctly for me... Here's what I have got: <html> <body> <form method=post> <textarea name="str" cols=50 rows=10></textarea><br> <input type=submit> </form> <hr><pre> <?php $str = ereg_replace("([^\r\n])\r\n([^\r\n])", "\\1 \\2", $str); echo $str; ?> </pre> </body> </html> I pasted your text into the textarea and submitted it: This is a story of how the West was won. Not about the Brady bunch but how those guys with guns somehow won. I don't know who won, but I do know the West was won. So the West is number one. Yay. And it outputted: This is a story of how the West was won. Not about the Brady bunch but how those guys with guns somehow won. I don\'t know who won, but I do know the West was won. So the West is number one. Yay. (Just need to run it through stripslashes() to fix the don\'t.) Does this not work for you? Some troubleshooting ideas: <?php $str = ereg_replace("\r", "CR", $str); // replace CRs with "CR" $str = ereg_replace("\n", "LF", $str); // replace LFs with "LF" ?> <?php echo urlencode($str); // may help to highlight any special characters in the string ?> Hope this helps Simon Garner

« previous php.general (#41645) next »