|
Re: Need help with updating ereg_replace function -> to preg_replace [message #180583 is a reply to message #180582] |
Fri, 01 March 2013 09:00   |
|
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 09:17   |
|
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 10:24   |
daveh
Messages: 18 Registered: March 2013
Karma: 0
|
Junior Member |
add to buddy list ignore all messages by this user
|
|
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 11:09   |
daveh
Messages: 18 Registered: March 2013
Karma: 0
|
Junior Member |
add to buddy list ignore all messages by this user
|
|
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 05:39   |
|
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 00:53  |
Denis McMahon
Messages: 634 Registered: September 2010
Karma: 0
|
Senior Member |
add to buddy list ignore all messages by this user
|
|
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
|
|
|