On 11/29/10 09:10, Richard Quadling wrote:
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 :
Apologies for the delay.
That works, except it will catch all instances. I need it to catch the
last number specifically and not the period. The output will also output
a previous and new reading- I need the new reading. And I also need to
allow for the possibility of a period. So.... here's what I have:
/(\d++)[^.]?$
Which works as long as there is no period at the end. I just can't seem
to get my head around it. I need a guru... :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php