Re: preg_match fails to resolve variable as a subject
| From: | Da Rock | Date: | Sat, 27 Nov 2010 04:45:47 +0000 |
| Subject: | Re: preg_match fails to resolve variable as a subject | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309698@lists.php.net to get a copy of this message | ||
On 11/27/10 13:51, Tamara Temple wrote:
On Nov 26, 2010, at 7:28 PM, Da Rock wrote: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.On 11/27/10 00:57, Richard Quadling wrote:$ 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 orOn 26 November 2010 00:07, Da Rock<php-list@herveybayaustralia.com.au> wrote:Haven't tried yet, but isn't that what $ is for? End of line?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.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 \.