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 #181959 is a reply to message #181957] Fri, 28 June 2013 09:02 Go to previous messageGo to previous message
tony is currently offline  tony
Messages: 19
Registered: December 2010
Karma:
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
[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: Fri Nov 22 08:03:18 GMT 2024

Total time taken to generate the page: 0.04271 seconds