PDA

View Full Version : Preg match help required.


ramki067
05-27-2008, 07:22 AM
HI,
I need to match the below $value but their is something wrong in the preg_match i've written its not matching somehow! Can anybody help?


$value = "1920x1080i";
preg_match('/[0-9]x[0-9]/D/i',$value)


Thanks,
ramki.

Iszak
05-27-2008, 07:57 AM
Well you haven't specified if you want it to find exactly "1920x1080i" or what. So if you can give me what you want to be found and examples of strings put in I can help.

ramki067
05-27-2008, 08:11 AM
Thanks. It not exactly the value of $value, but its like this:

[digits] x [digits and/or character at the end]
Ex:1. 800 x 600i
2. 800 x 600
3. 1930x1100i
4. 1920x1100

Regards,
Ramki.

Iszak
05-27-2008, 09:06 AM
Ok here is the test to make sure it pasted all expectations

<?php

$value = "
800 x 600i
800 x 600
1930x1100
1920x1100
";
preg_match_all("/([0-9]+\s?x\s?[0-9]+[A-Z]?)/si",$value, $matches);
print_r($matches); // Array ( [0] => 800 x 600i [1] => 800 x 600 [2] => 1930x1100 [3] => 1920x1100 ) )

?>


and with a single input


<?php

$value = "800 x 600i";
preg_match("/([0-9]+\s?x\s?[0-9]+[A-Z]?)/si",$value, $matches);
print_r($matches); // Array ( [0] => 800 x 600i [1] => 800 x 600i )

?>


Also I might not that you didn't specific how many digit it's going to be so it can be more than 4 digits or only 2 or so. Thank me if this helped.