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
Switch to threaded view of this topic Create a new topic Submit Reply
how to change old ereg? [message #181937] Wed, 26 June 2013 04:41 Go to next message
astrid.kuhr is currently offline  astrid.kuhr
Messages: 5
Registered: June 2013
Karma: 0
Junior Member
Hello!

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.

} elseif (ereg_match('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$',
$temp_visibility_miles . ' ' . $part, $regs)) {

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?

Regards, Astrid
Re: how to change old ereg? [message #181938 is a reply to message #181937] Wed, 26 June 2013 09:47 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
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
Re: how to change old ereg? [message #181939 is a reply to message #181937] Wed, 26 June 2013 11:29 Go to previous messageGo to next message
astrid.kuhr is currently offline  astrid.kuhr
Messages: 5
Registered: June 2013
Karma: 0
Junior Member
Hello!

Sorry, it was a misstyping.

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?

Regards, Astrid
Re: how to change old ereg? [message #181940 is a reply to message #181939] Wed, 26 June 2013 11:57 Go to previous messageGo to next message
tony is currently offline  tony
Messages: 19
Registered: December 2010
Karma: 0
Junior Member
In article <8e2894b4-16cf-4599-af33-391fc6570124(at)googlegroups(dot)com>,
Astrid <astrid(dot)kuhr(at)gmail(dot)com> wrote:
> Hello!
>
> Sorry, it was a misstyping.
>
> 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.

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 //

Cheers
Tony
--
Tony Mountifield
Work: tony(at)softins(dot)co(dot)uk - http://www.softins.co.uk
Play: tony(at)mountifield(dot)org - http://tony.mountifield.org
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 next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
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>
Re: how to change old ereg? [message #181942 is a reply to message #181937] Wed, 26 June 2013 12:24 Go to previous messageGo to next message
astrid.kuhr is currently offline  astrid.kuhr
Messages: 5
Registered: June 2013
Karma: 0
Junior Member
Hello Tony,

thank you very much.
Now it works very well again. :)

Regards, Astrid
PREG \d vs. [0-9] (was: how to change old ereg?) [message #181943 is a reply to message #181941] Wed, 26 June 2013 14:42 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Thomas 'PointedEars' Lahn wrote:
> Tony Mountifield wrote:
>
>> 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)(…

Isn't the exact interpretation of \d locale dependent? I was not able
to find this information on php.net and I am not able to verify this, as
I do not have locales available, which have decimal digits other than
0-9. However, at least when one works with UTF-8 encoded strings and
uses the u modifier for the regular expression, \d is not the same as [0-9]:

>>> $zero = "\xe0\xa5\xa6" // DEVANAGARI DIGIT ZERO
>>> preg_match('/[0-9]/u', $zero)
0
>>> preg_match('/\d/u', $zero)
1

--
Christoph M. Becker
Re: PREG \d vs. [0-9] [message #181944 is a reply to message #181943] Wed, 26 June 2013 16:02 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Christoph Michael Becker wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Tony Mountifield wrote:
>>> 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)(…
>
> Isn't the exact interpretation of \d locale dependent? I was not able
> to find this information on php.net and I am not able to verify this, as
> I do not have locales available, which have decimal digits other than
> 0-9. However, at least when one works with UTF-8 encoded strings and
> uses the u modifier for the regular expression, \d is not the same as
> [0-9]:
>
>>>> $zero = "\xe0\xa5\xa6" // DEVANAGARI DIGIT ZERO
>>>> preg_match('/[0-9]/u', $zero)
> 0
>>>> preg_match('/\d/u', $zero)
> 1

PHP uses Perl-Compatible Regular Expressions (PCRE) here:

<http://php.net/preg_match>
<http://php.net/pcre>

So this can be found in greater detail in the PCRE documentation:

<http://pcre.org/pcre.txt>

“\d” can match more than just “0” to “9” in PCRE, but (unlike in Perl [1])
the behavior is _not_ locale-dependent by default. There is a flag,
PCRE_UCP, to let \d be equivalent to \p{Digit} etc. (UCP stands for “Unicode
Character Properties”), but apparently it is not set at compile-time for the
default PHP distribution:

$ locale
LANG=de_CH.UTF-8
LANGUAGE=
LC_CTYPE="de_CH.UTF-8"
LC_NUMERIC="de_CH.UTF-8"
LC_TIME="de_CH.UTF-8"
LC_COLLATE="de_CH.UTF-8"
LC_MONETARY="de_CH.UTF-8"
LC_MESSAGES=en_US.UTF-8
LC_PAPER="de_CH.UTF-8"
LC_NAME="de_CH.UTF-8"
LC_ADDRESS="de_CH.UTF-8"
LC_TELEPHONE="de_CH.UTF-8"
LC_MEASUREMENT="de_CH.UTF-8"
LC_IDENTIFICATION="de_CH.UTF-8"
LC_ALL=

$ php -r 'echo setlocale(LC_ALL, "de_CH.UTF-8") . "\n";
echo preg_match("/\d/", "१");'
de_CH.UTF-8
0

The “u” expression flag in PHP sets the PCRE_UTF8 run-time flag (as
documented), but apparently the PCRE_UCP run-time flag as well. Hence your
observation:

$ php -r 'echo preg_match("/\d/u", "१");'
1

$ php -v
PHP 5.4.15-1 (cli) (built: May 12 2013 12:17:45)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with XCache v3.0.1, Copyright (c) 2005-2013, by mOo
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
with XCache Optimizer v3.0.1, Copyright (c) 2005-2013, by mOo
with XCache Cacher v3.0.1, Copyright (c) 2005-2013, by mOo
with XCache Coverager v3.0.1, Copyright (c) 2005-2013, by mOo

In Perl there is the “a” flag to let Perl regular expressions match in ASCII
mode regardless of the locale, but it is not needed with PCRE (when PCRE_UCP
is not set at compile-time).

[1] <http://perldoc.perl.org/perlre.html>


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>
Re: how to change old ereg? [message #181945 is a reply to message #181940] Wed, 26 June 2013 19:34 Go to previous messageGo to next message
Gregor Kofler is currently offline  Gregor Kofler
Messages: 69
Registered: September 2010
Karma: 0
Member
Am 26.06.2013 13:57, Tony Mountifield meinte:

[snip]

> 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.
>
> Try this:
>
> } elseif (preg_match('/^M?(([0-9]?)[ ]?([0-9])(\/?)([0-9]*))SM$/',

Or use an (in this case) "unambigious" delimiter like '~', '#', etc.

http://php.net/manual/en/regexp.reference.delimiters.php


Gregor
Re: how to change old ereg? [message #181946 is a reply to message #181945] Wed, 26 June 2013 23:18 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Gregor Kofler wrote:

> Am 26.06.2013 13:57, Tony Mountifield meinte:
>> 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.
>>
>> Try this:
>>
>> } elseif (preg_match('/^M?(([0-9]?)[ ]?([0-9])(\/?)([0-9]*))SM$/',
>
> Or use an (in this case) "unambigious" delimiter like '~', '#', etc.

The word you were looking for is “unambiguous”.

> http://php.net/manual/en/regexp.reference.delimiters.php

Or use

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

to be safe.

(There must be an error in the Matrix.)


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>
Re: how to change old ereg? [message #181947 is a reply to message #181946] Thu, 27 June 2013 11:55 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 27/06/13 00:18, Thomas 'PointedEars' Lahn wrote:
> Gregor Kofler wrote:
>
>>
>> Or use an (in this case) "unambigious" delimiter like '~', '#', etc.
> The word you were looking for is “unambiguous”.
>

Or 'unique' :-)

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
Re: how to change old ereg? [message #181957 is a reply to message #181937] Fri, 28 June 2013 08:38 Go to previous messageGo to next message
astrid.kuhr is currently offline  astrid.kuhr
Messages: 5
Registered: June 2013
Karma: 0
Junior Member
Hello!

First all error-messages have gone now.
But now there is one coming back:

Notice: Undefined offset: 6 in /var/www/html/phpweather/phpweather.php on line 446

Notice: Undefined offset: 7 in /var/www/html/phpweather/phpweather.php on line 447

elseif (preg_match('#^(VC)?' . /* Proximity */
'(-|\+)?' . /* Intensity */
'(MI|PR|BC|DR|BL|SH|TS|FZ)?' . /* Descriptor */
'((DZ|RA|SN|SG|IC|PL|GR|GS|UP)+)?' . /* Precipitation */
'(BR|FG|FU|VA|DU|SA|HZ|PY)?' . /* Obscuration */
'(PO|SQ|FC|SS)?$#', /* Other */
$part, $regs)) {
/*
* Current weather-group.
*/
$decoded_metar['weather'][] =
array('proximity' => $regs[1],
'intensity' => $regs[2],
'descriptor' => $regs[3],
'precipitation' => $regs[4],
'obscuration' => $regs[6], /* line 446 */
'other' => $regs[7]);

}

I tried with several delimiters, but the error is there.
How can I get it work?

Regards, Astrid
Re: how to change old ereg? [message #181959 is a reply to message #181957] Fri, 28 June 2013 09:02 Go to previous messageGo to next message
tony is currently offline  tony
Messages: 19
Registered: December 2010
Karma: 0
Junior Member
In article <71279fa6-1958-4b61-8758-14af767b1993(at)googlegroups(dot)com>,
Astrid <astrid(dot)kuhr(at)gmail(dot)com> wrote:
> Hello!
>
> First all error-messages have gone now.
> But now there is one coming back:
>
> Notice: Undefined offset: 6 in /var/www/html/phpweather/phpweather.php on line 446
>
> Notice: Undefined offset: 7 in /var/www/html/phpweather/phpweather.php on line 447
>
> elseif (preg_match('#^(VC)?' . /* Proximity */
> '(-|\+)?' . /* Intensity */
> '(MI|PR|BC|DR|BL|SH|TS|FZ)?' . /* Descriptor */
> '((DZ|RA|SN|SG|IC|PL|GR|GS|UP)+)?' . /* Precipitation */
> '(BR|FG|FU|VA|DU|SA|HZ|PY)?' . /* Obscuration */
> '(PO|SQ|FC|SS)?$#', /* Other */
> $part, $regs)) {
> /*
> * Current weather-group.
> */
> $decoded_metar['weather'][] =
> array('proximity' => $regs[1],
> 'intensity' => $regs[2],
> 'descriptor' => $regs[3],
> 'precipitation' => $regs[4],
> 'obscuration' => $regs[6], /* line 446 */
> 'other' => $regs[7]);
>
> }
>
> I tried with several delimiters, but the error is there.
> How can I get it work?

That probably means the optional Obscuration and Other were not present.
Since nothing matched those parenthesised options, the corresponding
captures were not put in the array.

The quick and dirty solution, which I think is adequate in this instance,
is to use @ to suppress the specific errors and allow the value to be null:

array('proximity' => @$regs[1],
'intensity' => @$regs[2],
'descriptor' => @$regs[3],
'precipitation' => @$regs[4],
'obscuration' => @$regs[6], /* line 446 */
'other' => @$regs[7]);

You should only use @ to suppress errors you already understand, and as
close as possible to the specific location.

Cheers
Tony
--
Tony Mountifield
Work: tony(at)softins(dot)co(dot)uk - http://www.softins.co.uk
Play: tony(at)mountifield(dot)org - http://tony.mountifield.org
Re: how to change old ereg? [message #181961 is a reply to message #181937] Fri, 28 June 2013 09:46 Go to previous messageGo to next message
astrid.kuhr is currently offline  astrid.kuhr
Messages: 5
Registered: June 2013
Karma: 0
Junior Member
Hello Tony,

yes, this did it. :)
Thank you very much.

Regards, Astrid
Re: how to change old ereg? [message #181962 is a reply to message #181959] Fri, 28 June 2013 10:39 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Tony Mountifield wrote:

> Astrid <astrid(dot)kuhr(at)gmail(dot)com> wrote:
>> First all error-messages have gone now.
>> But now there is one coming back:
>>
>> Notice: Undefined offset: 6 in /var/www/html/phpweather/phpweather.php on
>> line 446
>>
>> Notice: Undefined offset: 7 in /var/www/html/phpweather/phpweather.php on
>> line 447
>>
>> elseif (preg_match('#^(VC)?' . /* Proximity */
>> '(-|\+)?' . /* Intensity */
>> '(MI|PR|BC|DR|BL|SH|TS|FZ)?' . /* Descriptor */
>> '((DZ|RA|SN|SG|IC|PL|GR|GS|UP)+)?' . /* Precipitation */
>> '(BR|FG|FU|VA|DU|SA|HZ|PY)?' . /* Obscuration */
>> '(PO|SQ|FC|SS)?$#', /* Other */
>> $part, $regs)) {
>> /*
>> * Current weather-group.
>> */
>> $decoded_metar['weather'][] =
>> array('proximity' => $regs[1],
>> 'intensity' => $regs[2],
>> 'descriptor' => $regs[3],
>> 'precipitation' => $regs[4],
>> 'obscuration' => $regs[6], /* line 446 */
>> 'other' => $regs[7]);
>>
>> }
>>
>> I tried with several delimiters, but the error is there.
>> How can I get it work?
>
> That probably means the optional Obscuration and Other were not present.
> Since nothing matched those parenthesised options, the corresponding
> captures were not put in the array.
>
> The quick and dirty solution, which I think is adequate in this instance,

Why?

> is to use @ to suppress the specific errors and allow the value to be
> null:
>
> array('proximity' => @$regs[1],
> 'intensity' => @$regs[2],
> 'descriptor' => @$regs[3],
> 'precipitation' => @$regs[4],
> 'obscuration' => @$regs[6], /* line 446 */
> 'other' => @$regs[7]);
>
> You should only use @ to suppress errors you already understand, and as
> close as possible to the specific location.

Or you could disable notices (they are _not_ error messages) entirely for
production, and enable them only for development, as it is recommended.

However, I have also received harmless Notices in development that hindered
development more than they helped because they broke the layout. In that
case I have used

if (defined('DEBUG') && DEBUG > 0)
{
error_reporting(error_reporting() & ~E_NOTICE);
}

/* code generating harmless notices */

if (defined('DEBUG') && DEBUG > 0)
{
error_reporting(error_reporting() | E_NOTICE);
}

This approach allows you to just set the debug level to toggle development
behavior instead of changing the (entire) code before deploying to
production. In my PHPX MVC framework, which is used by my ECMAScript
Support Matrix [1], and in the Matrix itself, DEBUG === 1 enables simple
debug messages, and DEBUG > 2 also enables database framework debug
messages.


PointedEars
___________
[1] <http://PointedEars.de/es-matrix>
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Re: how to change old ereg? [message #181963 is a reply to message #181959] Fri, 28 June 2013 11:08 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 28 Jun 2013 09:02:50 +0000, Tony Mountifield wrote:

> In article <71279fa6-1958-4b61-8758-14af767b1993(at)googlegroups(dot)com>,
> Astrid <astrid(dot)kuhr(at)gmail(dot)com> wrote:
>> Hello!
>>
>> First all error-messages have gone now.
>> But now there is one coming back:
>>
>> Notice: Undefined offset: 6 in /var/www/html/phpweather/phpweather.php
>> on line 446
>>
>> Notice: Undefined offset: 7 in /var/www/html/phpweather/phpweather.php
>> on line 447
>>
>> elseif (preg_match('#^(VC)?' . /* Proximity
>> */
>> '(-|\+)?' . /* Intensity */
>> '(MI|PR|BC|DR|BL|SH|TS|FZ)?' . /* Descriptor */
>> '((DZ|RA|SN|SG|IC|PL|GR|GS|UP)+)?' . /*
Precipitation */
>> '(BR|FG|FU|VA|DU|SA|HZ|PY)?' . /* Obscuration
*/
>> '(PO|SQ|FC|SS)?$#', /* Other */
$part, $regs))
>> {
>> /*
>> * Current weather-group.
>> */
>> $decoded_metar['weather'][] =
>> array('proximity' => $regs[1],
>> 'intensity' => $regs[2],
>> 'descriptor' => $regs[3],
>> 'precipitation' => $regs[4],
>> 'obscuration' => $regs[6], /* line 446 */
>> 'other' => $regs[7]);
>>
>> }
>>
>> I tried with several delimiters, but the error is there.
>> How can I get it work?
>
> That probably means the optional Obscuration and Other were not present.
> Since nothing matched those parenthesised options, the corresponding
> captures were not put in the array.
>
> The quick and dirty solution, which I think is adequate in this
> instance, is to use @ to suppress the specific errors and allow the
> value to be null:
>
> array('proximity' => @$regs[1],
> 'intensity' => @$regs[2],
> 'descriptor' => @$regs[3],
> 'precipitation' => @$regs[4],
> 'obscuration' => @$regs[6], /* line 446 */
> 'other' => @$regs[7]);
>
> You should only use @ to suppress errors you already understand, and as
> close as possible to the specific location.

Observation

This assumes that obscuration and other are the missing entities, and not
eg intensity and precipitation.

A better method might be to check count($regs), and if it's less than
expected (8)?, walk through the members from $regs[1] to $regs[last]
assigning them to array members based on their values.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: how to change old ereg? [message #181964 is a reply to message #181961] Fri, 28 June 2013 12:48 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/28/2013 5:46 AM, Astrid wrote:
> Hello Tony,
>
> yes, this did it. :)
> Thank you very much.
>
> Regards, Astrid
>

Astrid,

Please see Dennis's reply. IMHO, Tony's "quick and dirty" solution is
just that - and can cause numerous problems later. It is almost never a
good idea to suppress messages; it is better to fix them now, because if
you don't, almost surely you'll have to fix them later.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Sat Nov 23 10:21:45 GMT 2024

Total time taken to generate the page: 0.02621 seconds