From: Jim Lucas on
Shreyas Agasthya wrote:
> Then, when does one use ereg_replace as against preg_replace? I read from
> one the forums that preg_* is faster and ereg_* is if not faster but
> simpler.

BUT, all the ereg_* has been depricated. DO NOT USE THEM if you want your code
to work in the future. :)

>
> Is that it?
>
> Regards,
> Shreyas
>
>
>
> On Tue, Jun 22, 2010 at 9:58 PM, Richard Quadling <rquadling(a)gmail.com>wrote:
>
>> "A "word" character is any letter or digit or the underscore
>> character, that is, any character which can be part of a Perl "word".
>> The definition of letters and digits is controlled by PCRE's character
>> tables, and may vary if locale-specific matching is taking place. For
>> example, in the "fr" (French) locale, some character codes greater
>> than 128 are used for accented letters, and these are matched by \w."
>>
>> The above becomes ...
>>
>> _A _word_ character is any letter or digit or the underscore
>> character_ that is_ any character which can be part of a Perl _word__
>> The definition of letters and digits is controlled by PCRE_s character
>> tables_ and may vary if locale_specific matching is taking place_ For
>> example_ in the _fr_ _French_ locale_ some character codes greater
>> than 128 are used for accented letters_ and these are matched by _w__
>>
>> --
>> -----
>> Richard Quadling
>> "Standing on the shoulders of some very clever giants!"
>> EE : http://www.experts-exchange.com/M_248814.html
>> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
>> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>


--
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
From: Rick Dwyer on


On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:
>
> It is clean, but as Richard mentioned, it won't handle strings
> outside of the traditional 128 ASCII range, so accented characters
> and the like will be converted to an underscore. Also, spaces might
> become an issue.
>
> However, if you are happy that your input won't go beyond the a-z0-9
> range, then it should do what you need.

No, actually I'm fairly confident characters outside the 128 range are
what are causing me problems now.

So I will try Richard's method.

Thanks to all.

--Rick

From: Rick Dwyer on
Hello again list.

My code for stripping characters is below. I'm hoping to get feedback
as to how rock solid it will provide the desired output under any
circumstance:

My output must look like this (no quotes):

"This-is-my-string-with-lots-of-junk-characters-in-it"

The code with string looks like this:

$old_string = 'ééééThis is my & $string -- with ƒ
lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®†
¥¨ˆøπ“‘ååååååß∂ƒ©˙∆˚¬…æ`````````__________';

$find = '/[^a-z0-9]/i';
$replace = ' ';

$new_string = preg_replace($find, $replace, $old_string);
$new_string = preg_replace("/ {2,}/", "-", $new_string);
$new_string = preg_replace("/ {1,}/", "-", $new_string);

$new_string = rtrim($new_string, "-");
$new_string = ltrim($new_string, "-");


echo $new_string;

Will the logic above capture and remove every non alpha numeric
character and place a SINGLE hyphen between the non contiguous alpha
numeric characters?

Thanks for the help on this.


--Rick


On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:

>
>
> On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:
>>
>> It is clean, but as Richard mentioned, it won't handle strings
>> outside of the traditional 128 ASCII range, so accented characters
>> and the like will be converted to an underscore. Also, spaces might
>> become an issue.
>>
>> However, if you are happy that your input won't go beyond the a-
>> z0-9 range, then it should do what you need.
>
> No, actually I'm fairly confident characters outside the 128 range
> are what are causing me problems now.
>
> So I will try Richard's method.
>
> Thanks to all.
>
> --Rick
>

From: Ashley Sheridan on
On Tue, 2010-06-22 at 20:03 -0400, Rick Dwyer wrote:

> Hello again list.
>
> My code for stripping characters is below. I'm hoping to get feedback
> as to how rock solid it will provide the desired output under any
> circumstance:
>
> My output must look like this (no quotes):
>
> "This-is-my-string-with-lots-of-junk-characters-in-it"
>
> The code with string looks like this:
>
> $old_string = 'ééééThis is my & $string -- with ƒ
> lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®†
> ¥¨ˆøπ“‘ååååååß∂ƒ©˙∆˚¬…æ`````````__________';
>
> $find = '/[^a-z0-9]/i';
> $replace = ' ';
>
> $new_string = preg_replace($find, $replace, $old_string);
> $new_string = preg_replace("/ {2,}/", "-", $new_string);
> $new_string = preg_replace("/ {1,}/", "-", $new_string);
>
> $new_string = rtrim($new_string, "-");
> $new_string = ltrim($new_string, "-");
>
>
> echo $new_string;
>
> Will the logic above capture and remove every non alpha numeric
> character and place a SINGLE hyphen between the non contiguous alpha
> numeric characters?
>
> Thanks for the help on this.
>
>
> --Rick
>
>
> On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:
>
> >
> >
> > On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:
> >>
> >> It is clean, but as Richard mentioned, it won't handle strings
> >> outside of the traditional 128 ASCII range, so accented characters
> >> and the like will be converted to an underscore. Also, spaces might
> >> become an issue.
> >>
> >> However, if you are happy that your input won't go beyond the a-
> >> z0-9 range, then it should do what you need.
> >
> > No, actually I'm fairly confident characters outside the 128 range
> > are what are causing me problems now.
> >
> > So I will try Richard's method.
> >
> > Thanks to all.
> >
> > --Rick
> >
>
>


You can remove the second line of code, as the third one is replacing
what line 2 does anyway.

Also, instead of a rtrim and ltrim, you can merge the two with a single
call to trim, which will work on both ends of the string at once.

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Rick Dwyer on
Very good.
Thank you.

--Rick


On Jun 22, 2010, at 8:14 PM, Ashley Sheridan wrote:

> On Tue, 2010-06-22 at 20:03 -0400, Rick Dwyer wrote:
>>
>> Hello again list.
>>
>> My code for stripping characters is below. I'm hoping to get
>> feedback
>> as to how rock solid it will provide the desired output under any
>> circumstance:
>>
>> My output must look like this (no quotes):
>>
>> "This-is-my-string-with-lots-of-junk-characters-in-it"
>>
>> The code with string looks like this:
>>
>> $old_string = 'ééééThis is my & $string -- with ƒ
>> lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®†
>> ¥¨ˆøπ“‘ååååååß∂ƒ©˙∆˚¬…
>> æ`````````__________';
>>
>> $find = '/[^a-z0-9]/i';
>> $replace = ' ';
>>
>> $new_string = preg_replace($find, $replace, $old_string);
>> $new_string = preg_replace("/ {2,}/", "-", $new_string);
>> $new_string = preg_replace("/ {1,}/", "-", $new_string);
>>
>> $new_string = rtrim($new_string, "-");
>> $new_string = ltrim($new_string, "-");
>>
>>
>> echo $new_string;
>>
>> Will the logic above capture and remove every non alpha numeric
>> character and place a SINGLE hyphen between the non contiguous alpha
>> numeric characters?
>>
>> Thanks for the help on this.
>>
>>
>> --Rick
>>
>>
>> On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:
>>
>> >
>> >
>> > On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:
>> >>
>> >> It is clean, but as Richard mentioned, it won't handle strings
>> >> outside of the traditional 128 ASCII range, so accented characters
>> >> and the like will be converted to an underscore. Also, spaces
>> might
>> >> become an issue.
>> >>
>> >> However, if you are happy that your input won't go beyond the a-
>> >> z0-9 range, then it should do what you need.
>> >
>> > No, actually I'm fairly confident characters outside the 128 range
>> > are what are causing me problems now.
>> >
>> > So I will try Richard's method.
>> >
>> > Thanks to all.
>> >
>> > --Rick
>> >
>>
>>
>
> You can remove the second line of code, as the third one is
> replacing what line 2 does anyway.
>
> Also, instead of a rtrim and ltrim, you can merge the two with a
> single call to trim, which will work on both ends of the string at
> once.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>