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 #181963 is a reply to message #181959] Fri, 28 June 2013 11:08 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
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
[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 Feb 16 12:08:59 GMT 2025

Total time taken to generate the page: 0.04325 seconds