FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How do I do this search and replace?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How do I do this search and replace? [message #172302 is a reply to message #172300] Sat, 12 February 2011 22:03 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On 12/02/11 21:15, laredotornado(at)zipmail(dot)com wrote:
> Hi,
>
> I'm using PHP 5. I want to search for all instances of the "\n"
> character in my $contents variable and replace it with "\r\n".
> However, I do not want to replace the "\n" if the character
> immediately before is already a "\r". How would I construct such a
> search and replace to do this?

One or more of these may work, determining which is best for your
application is up to you, they are all variations on a theme.

$contents = preg_replace("\n","\r\n",preg_replace("\r","",$contents);

$contents = preg_replace("\n","\r\n",preg_replace("\r\n","\n",$contents);

$contents = preg_replace("\n","\r\n",preg_replace("\r+\n","\n",$contents);

$contents =
preg_replace("\n","\r\n",preg_replace("(\r+\n+)+","\n",$contents);

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Curious problem
Next Topic: Hot Sameera Hot Cleavage show - Download
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 08:34:55 GMT 2024

Total time taken to generate the page: 0.05071 seconds