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

Home » Imported messages » comp.lang.php » Need help with updating ereg_replace function -> to preg_replace
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Need help with updating ereg_replace function -> to preg_replace [message #180582] Fri, 01 March 2013 13:10 Go to next message
daveh is currently offline  daveh
Messages: 18
Registered: March 2013
Karma: 0
Junior Member
Hello

I'm totally confused none of the examples I've googled seem to help with fixing the following line of code:

$myfunc = ereg_replace("0+$", "", $data);

I've tried $myfunc = preg_replace("/0+$/", "/", $data);

Please any help would be appreciated as I did not write this code and really still trying to figure out regex functions.

Thanks,

Dave
Re: Need help with updating ereg_replace function -> to preg_replace [message #180583 is a reply to message #180582] Fri, 01 March 2013 14:00 Go to previous messageGo to next message
Michael Vilain is currently offline  Michael Vilain
Messages: 88
Registered: September 2010
Karma: 0
Member
In article <fbab9879-db62-4cef-80e9-71a2c0d4aecd(at)googlegroups(dot)com>,
daveh(at)allheller(dot)net wrote:

> Hello
>
> I'm totally confused none of the examples I've googled seem to help with
> fixing the following line of code:
>
> $myfunc = ereg_replace("0+$", "", $data);
>
> I've tried $myfunc = preg_replace("/0+$/", "/", $data);
>
> Please any help would be appreciated as I did not write this code and really
> still trying to figure out regex functions.
>
> Thanks,
>
> Dave

Where have you looked to try to find the function descriptions for the
php replace functions?

From php.org, there's a big warning not to use ereg_replace because it's
deprecated in php 5.3. It uses the POSIX regex pattern matching style
to do the string matching and replace.

http://www.php.net/manual/en/function.ereg-replace.php

preg_replace uses the PERL string matching symantics which is slightly
different from POSIX. It's also more robust, but it used to be slower
than the ereg functions but that might not be the case any more.

http://www.php.net/manual/en/function.preg-replace.php

What part of this is confusing you?

--
DeeDee, don't press that button! DeeDee! NO! Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]
Re: Need help with updating ereg_replace function -> to preg_replace [message #180584 is a reply to message #180582] Fri, 01 March 2013 14:17 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
daveh wrote:

> I'm totally confused none of the examples I've googled seem to help with fixing the following line of code:
>
> $myfunc = ereg_replace("0+$", "", $data);
>
> I've tried $myfunc = preg_replace("/0+$/", "/", $data);

You should try the following:

$myfunc = preg_replace('/0+$/', '', $data);

If you have more ereg_*() to replace, you should really learn the
workings of ereg_*() /and/ preg_*() /and/ string literals to be able to
transcribe them; the manual on <http://www.php.net/manual/en/> is a good
lecture. Just googling for some examples probably won't suffice.

--
Christoph M. Becker
Re: Need help with updating ereg_replace function -> to preg_replace [message #180585 is a reply to message #180582] Fri, 01 March 2013 15:24 Go to previous messageGo to next message
daveh is currently offline  daveh
Messages: 18
Registered: March 2013
Karma: 0
Junior Member
On Friday, March 1, 2013 8:10:07 AM UTC-5, da...@allheller.net wrote:
> Hello
>
>
>
> I'm totally confused none of the examples I've googled seem to help with fixing the following line of code:
>
>
>
> $myfunc = ereg_replace("0+$", "", $data);
>
>
>
> I've tried $myfunc = preg_replace("/0+$/", "/", $data);
>
>
>
> Please any help would be appreciated as I did not write this code and really still trying to figure out regex functions.
>
>
>
> Thanks,
>
>
>
> Dave

Thanks for all the help. "str_replace" works as a direct drop in replacement for "ereg_replace"
Re: Need help with updating ereg_replace function -> to preg_replace [message #180586 is a reply to message #180585] Fri, 01 March 2013 16:09 Go to previous messageGo to next message
daveh is currently offline  daveh
Messages: 18
Registered: March 2013
Karma: 0
Junior Member
On Friday, March 1, 2013 10:24:55 AM UTC-5, da...@allheller.net wrote:
> On Friday, March 1, 2013 8:10:07 AM UTC-5, da...@allheller.net wrote:
>
>> Hello
>
>>
>
>>
>
>>
>
>> I'm totally confused none of the examples I've googled seem to help with fixing the following line of code:
>
>>
>
>>
>
>>
>
>> $myfunc = ereg_replace("0+$", "", $data);
>
>>
>
>>
>
>>
>
>> I've tried $myfunc = preg_replace("/0+$/", "/", $data);
>
>>
>
>>
>
>>
>
>> Please any help would be appreciated as I did not write this code and really still trying to figure out regex functions.
>
>>
>
>>
>
>>
>
>> Thanks,
>
>>
>
>>
>
>>
>
>> Dave
>
>
>
> Thanks for all the help. "str_replace" works as a direct drop in replacement for "ereg_replace"

Actually this is what I did to fix it: $myfunc = str_replace('$+0+$', '', $data); !
Understanding what the code is trying to do makes a big difference. I did not write this code I'm just tasked with fixing it!
Re: Need help with updating ereg_replace function -> to preg_replace [message #180592 is a reply to message #180585] Mon, 04 March 2013 10:39 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Mar 1, 3:24 pm, da...@allheller.net wrote:
> On Friday, March 1, 2013 8:10:07 AM UTC-5, da...@allheller.net wrote:
>> Hello
>
>> I'm totally confused none of the examples I've googled seem to help with fixing the following line of code:
>
>> $myfunc = ereg_replace("0+$", "", $data);
>
>> I've tried $myfunc = preg_replace("/0+$/", "/", $data);
>
>> Please any help would be appreciated as I did not write this code and really still trying to figure out regex functions.
>
>> Thanks,
>
>> Dave
>
> Thanks for all the help. "str_replace" works as a direct drop in replacement for "ereg_replace"

It is no where near a direct drop replacement. What the ereg above
does is to remove trailing zeros (the $ sign means the end of the
line, it is not a literal $). Your str_replace will not do anything
like that.
Re: Need help with updating ereg_replace function -> to preg_replace [message #180617 is a reply to message #180582] Thu, 07 March 2013 05:53 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 01 Mar 2013 05:10:07 -0800, daveh wrote:

> Hello
>
> I'm totally confused none of the examples I've googled seem to help with
> fixing the following line of code:
>
> $myfunc = ereg_replace("0+$", "", $data);
>
> I've tried $myfunc = preg_replace("/0+$/", "/", $data);

I suspect that the preg_replace() equivalent of the above ereg_replace is
more likely to be:

$myfunc = preg_replace( "/0+$/", "", $data );

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Other source for help?
Next Topic: returning values from a 2d array
Goto Forum:
  

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

Current Time: Sat Nov 30 01:43:12 GMT 2024

Total time taken to generate the page: 0.02800 seconds