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

Home » Imported messages » comp.lang.php » how to change old ereg?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: how to change old ereg? [message #181941 is a reply to message #181940] Wed, 26 June 2013 12:13 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Tony Mountifield wrote:

> Astrid <astrid(dot)kuhr(at)gmail(dot)com> wrote:
>> The original was:
>>
>> } elseif (ereg('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$',
>> $temp_visibility_miles . ' ' . $part, $regs)) {
>>
>> and I changed to
>>
>> } elseif (preg_match('/^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$/',
>> $temp_visibility_miles . ' ' . $part, $regs)) {
>>
>>
>> But then:
>>
>> Warning: preg_match() [function.preg-match]: Unknown modifier '?' in
>> /var/www/html/phpweather/phpweather.php on line 329
>>
>> And very very many other error-messages to.
>>
>> How can I change it to get it work?
>
> That's because you have an unescaped / within your regex, so it sees
> /^M?(([0-9]?)[ ]?([0-9])(/ followed by a ? as a regex modifier.

Good catch. Also, in POSIX Extended Regular Expressions (ERE) this is
written simpler

^M?(([0-9]?) ?([0-9])(…

and in Perl-Compatible Regular Expressions (PCRE) it is written simpler

^M?((\d?) ?(\d)(…

> Try this:
>
> } elseif (preg_match('/^M?(([0-9]?)[ ]?([0-9])(\/?)([0-9]*))SM$/',
>
> It wasn't a problem in ereg() because the regex didn't need to be enclosed
> in //

It should be noted that *any* delimiter *except* an alphanumeric character
and backslash may be used. This can help to make PCREs in PHP easier to
read:

preg_match('#^M?((\d?) ?(\d)(/?)(\d*))SM$#', …

See also: <http://php.net/preg_quote>.


PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom(at)94(dot)75(dot)214(dot)39>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: FORMS, validating mail was sent
Next Topic: $referrer = $_SERVER['HTTP_REFERER'] echo
Goto Forum:
  

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

Current Time: Sun Nov 24 14:45:08 GMT 2024

Total time taken to generate the page: 0.04007 seconds