RE: [PHP] ereg_replace help

This is a discussion on RE: [PHP] ereg_replace help within the PHP General forums, part of the PHP Programming Forums category; > * Thus wrote Martin Towell (martin.towell@world.net): > > Hi All, > > > > I have an ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-19-2003
Martin Towell
 
Posts: n/a
Default RE: [PHP] ereg_replace help

> * Thus wrote Martin Towell (martin.towell@world.net):
> > Hi All,
> >
> > I have an array of strings in the following format:
> > "abcd - rst"
> > "abcd - uvw"
> > "abcd - xyz"
> > "foobar - rst"
> > "blah - rst"
> > "googol - uvw"
> >
> > What I want to do is strip everything from the " - " bit of

> the string to
> > the end, _but_ only for the strings that don't start with "abcd"
> >
> > I was thinking something like the following:
> > echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n";
> > but obviously this doesn't work, otherwise I wouldn't be

> emailing the
> > list...
> >

>
> $newarray = preg_replace('/((?<!abcd) - (.*))$/', '\\3', $array);
>
> > Can anyone help? I need to use ereg_replace() because it's

> part of our code
> > library and therefore can't change :(

>
> How do you mean its part of your code library? I would strongly
> suggest using preg_* for its speed and capabilites.
>
> Curt



thanks for everyone's help...

> How do you mean its part of your code library?


I mean that the function I'm having to call is passed an array (coming from
a databse) and it has an option to do an ereg_replace() on the incoming
array. Due to the amount of other code relying on it, is very hard to change
without causing something strange to happen elsewhere :(

If all the code was mine, then I wouldn't have any reservations on changing
it in an instant. I'm having to improve the code gradually (good luck to me)

Martin
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:49 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0