RE: [PHP] Simple String Replace Question

From: Date: Mon, 26 Feb 2001 04:19:26 +0000
Subject: RE: [PHP] Simple String Replace Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41644@lists.php.net to get a copy of this message
> No, that doesn't make any sense whatsoever :) > > A \n *is* a new line. I can only guess you're getting confused because > there's \r's as well as \n's in the string. Try this: > > > <?php > $str = "abc\r\ndefg\r\n\r\nxyzpqr\r\njklmno"; > $str = ereg_replace("([^\r\n])\r\n([^\r\n])", "\\1 \\2", $str); > echo $str; > ?> 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. ----------- original text: 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. ----------- returned from your code: 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. ----------- what I want is: 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. ^that may wrap in your e-mail program

« previous php.general (#41644) next »