Re: how to change old ereg? [message #181938 is a reply to message #181937] |
Wed, 26 June 2013 09:47 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
astrid(dot)kuhr(at)gmail(dot)com wrote:
> On a webpage I am using phpweather.
> It works fine for several years.
> But now it causes very many error messages.
> I searched in the web, that ereg is not
> longer supported and it is to replace with
> preg_match.
> I try to do this and change
>
> if (ereg("^pw_${type}_([a-z][a-z])(_[A-Z][A-Z])?\.php$", $file, $regs)) {
> $output[$regs[1] . $regs[2]] = $languages[$regs[1] . $regs[2]];
> }
>
> to
>
> if (preg_match("/^pw_${type}_([a-z][a-z])(_[A-Z][A-Z])?\.php$/", $file,
> $regs)) {
> $output[$regs[1] . $regs[2]] = $languages[$regs[1] . $regs[2]];
> }
>
> But now appears:
>
> Notice: Undefined offset: 2 in /var/www/html/phpweather/pw_utilities.php
> on line 95
>
> But I do not know php.
Learn it.
> } elseif (ereg_match('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$',
> $temp_visibility_miles . ' ' . $part, $regs)) {
There is no built-in ereg_match() function.
> 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?
RTFM:
<http://php.net/ereg>
<http://php.net/preg_match>
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
|
|
|