Re: how to change old ereg? [message #181963 is a reply to message #181959] |
Fri, 28 June 2013 11:08 ![Go to previous message Go to previous message](/forum/theme/default/images/up.png) ![Go to next message Go to previous message](/forum/theme/default/images/down.png) |
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
|
|
|