Re: pcre little problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Nov 7, 2011 at 5:54 AM, Richard Quadling <rquadling@xxxxxxxxx> wrote:
> On 4 November 2011 16:52, QI.VOLMAR QI <qi.volmar@xxxxxxxxx> wrote:
>
>> i have this part of code that works with DOMDocument:
>>
>> public function translateNFeXML(NFE $nfe_factory) {
>>        $inf_adic = $nfe_factory->createElement('infAdic');
>>        if ($this->inf_ad_fisco) {
>>            $inf_adic_fisco =
>> $nfe_factory->createElement('infAdicFisco', $this->inf_ad_fisco);
>>            $inf_adic->appendChild($inf_adic_fisco);
>>        }
>>
>>        $string = "a=10&b[]=20&c=30n°&d=40+:50";
>>        die(preg_filter('/[^:][[:punct:]]/', '', $string));
>>        $inf_cpl = $nfe_factory->createElement('infCpl',
>> $this->inf_complementar);
>>
>> QUESTION: Why the preg_filter causes a end of the application, with no
>> error throwing (even in die don't appears nothing)?
>
>
> preg_filter() returns NULL if there are no matches and the subject is a
> string.
>
> And ...
>
> php -r "die(null);"
>
> outputs nothing.


Here:

>>        die(preg_filter('/[^:][[:punct:]]/', '', $string));

Did you really want to do this:

preg_filter('/[^:][[:punct:]]/', '', $string) or die("nothing returned\n");

???

See http://php.net/manual/en/function.preg-filter.php "Return values"
as Richard points out preg_filter returns NULL if there are no matched
in a string.

Now this is interesting:

>>        $string = "a=10&b[]=20&c=30n°&d=40+:50";

There is a wide character in that string following 30n. The preg
functions sometimes don't deal well with wide characters in my
experience (it's not 100% anyway), you probably need to use the mb_
functions instead.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux