Re: preg_match fails to resolve variable as a subject

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

 



On 27 November 2010 04:45, Da Rock <php-list@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> On 11/27/10 13:51, Tamara Temple wrote:
>>
>> On Nov 26, 2010, at 7:28 PM, Da Rock wrote:
>>
>>> On 11/27/10 00:57, Richard Quadling wrote:
>>>>
>>>> On 26 November 2010 00:07, Da Rock<php-list@xxxxxxxxxxxxxxxxxxxxxxxxx>
>>>> Âwrote:
>>>>
>>>>> preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . $command),&$matches)
>>>>>
>>>> Can you ...
>>>>
>>>> var_dump(exec($mixer . ' ' . $command));
>>>>
>>>> I wonder if the output includes a new line which you are not
>>>> accounting for in the regex.
>>>>
>>>>
>>> Haven't tried yet, but isn't that what $ is for? End of line?
>>>
>>
>>
>> $ matches end of line, but since your last match expression is to match
>> explicitly the character '.' before end of line, and there's a newline, it
>> won't match. Again, use trim() to get rid of the newline character at the
>> end of the string returned by exec(). Looking at the output or
>>
>>> And exec only gives one line- the last line of the output of the command.
>>> You have to provide a reference to an array for the entire output.
>>>
>>> var_dump gives:
>>> string(41) "Mixer vol is currently set to 75:75"
>>>
>>
>> It also looks like \d{1,3}\. won't match anything in the output string
>> given by the command.
>>
>>
>>
> Thank you for that- that did it. I removed the \.
>
> I am a little confused though; that regex was tested on several test sites
> and was deemed accurate on them, and one of them actually supplied the
> preg_match code. And if I run the command on a shell it actually outputs
> exactly the right subject for the regex- not to mention it got printed
> inadvertently (using system() ) via the php exactly the same. So I don't
> think I missed it somehow.
>
> What I have constantly seen come up (shell and php/html) is: Mixer vol is
> currently set to 75:75. (including the period)
>
> Don't get me wrong- you guys make sense; my system doesn't. I need to get to
> the bottom of this so I can ensure my code will port well. I don't want to
> get it all working and find it breaks when I run it on another system,
> albeit same OS (FreeBSD). Could be updates or variations of releases.
>
> Just to check again, I ran the command on the shell again and sure enough
> the period is no longer there- but I can't for the life of me figure out
> when that changed as this code has never worked (and yes, I added in the \.
> to match the end of line because it originally wasn't working). Another
> great mystery? Weird... :)
>
> Thanks again guys.

The regex is a valid regex. It's just useless for the data you are providing it.

I'm wondering what is missing from your output? The var_dump says the
text is a 41 character string, but the data you provided only has 36
characters in it.

What elements of the string do you want to capture?

/:(\d++)/ would catch the number after the :


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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