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

Home » Imported messages » comp.lang.php » help to debug a simple php preg_replace
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: help to debug a simple php preg_replace [message #172062 is a reply to message #172059] Fri, 28 January 2011 23:03 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On 28/01/11 18:46, Joe wrote:
> I found it - it's not regular expression or preg_replace construct,
> but my logic problem (multiple $hyprtext lines result in only the last
> one taking effect).

If you want to apply multiple preg_replaces one after the other, do the
following (and pay close attention to the var names used here):

<?php

$txt = preg_replace("/needle1/","replace1",$txt);
$txt = preg_replace("/needle2/","replace2",$txt);
$txt = preg_replace("/needle3/","replace3",$txt);
$txt = preg_replace("/needle4/","replace4",$txt);

?>

If you do what you did:

<?php

$txt2 = preg_replace("/needle1/","replace1",$txt);
$txt2 = preg_replace("/needle2/","replace2",$txt);
$txt2 = preg_replace("/needle3/","replace3",$txt);
$txt2 = preg_replace("/needle4/","replace4",$txt);

?>

Then you might as well just do this instead:

<?php

$txt2 = preg_replace("/needle4/","replace4",$txt);

?>

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Shri Shraddha Astrology
Next Topic: Asynchronous FTP Upload
Goto Forum:
  

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

Current Time: Tue Nov 26 11:24:57 GMT 2024

Total time taken to generate the page: 0.04292 seconds