|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
2nd pair of eyes
For what ever reason this is not working as far as i can tell it should be. Im just Trying to get everything between the specific <td class=\"back_build\"> tags. I told it to ignore the spaing with the \s* but it returns no results. Need a second pair of eyes to see what I may be missing.
Code:
<?
$string = " <td class=\"back_build\">
<font style=\"font-weight:bold;font-size:13px;\"></font>
<font class=\"cost_text\" style=\"font-size:11px;\">
<img src='images/pic5.png' align='absmiddle' alt='num1' title='num1'/> 92363 </font><br />
<font class=\"cost_text\" style=\"font-size:11px;\">
<img src='images/pic7.png' align='absmiddle' alt='num2' title='num2'/> 323270 </font><br />
<font class=\"cost_text\" style=\"font-size:11px;\">
<img src='images/pic6.png' align='absmiddle' alt='num3' title='num3'/> 129308 </font><br />
</td>
";
preg_match_all("/<td class=\"back_build\">\s*(.*?)\s*<\/td>/", $string, $matches);
print_r ($matches);
?>
|
|
#2
|
|||
|
|||
|
Try this:
Code:
preg_match_all("/<td class=\"back_build\">\s*(.*)\s*<\/td>/s", $string, $matches);
|
|
#3
|
|||
|
|||
|
Ahh the 'S' at the end.. thank you so much RuleMaker i figured it was something simple.
|
|
#4
|
|||
|
|||
|
No problem, just in case somebody doesn't know, the "s" flag indicates the multi-line search.
|
|
#5
|
|||
|
|||
|
Quote:
No, it does not. The 's' flag is also called the DOT-ALL flag. The 'm' is called the MULTI-LINE flag. |
|
#6
|
|||
|
|||
|
Quote:
Especially with the s-flag, the greedy DOT-STAR should be avoided (in this case). I'd advice the OP to at least make it reluctant as s/he already had in his/her original post: PHP Code:
Or (IMO) better yet, do: PHP Code:
Last edited by prometheuzz : August 18th, 2009 at 07:15 AM. |
|
#7
|
|||
|
|||
|
Quote:
We are talking about php, could you explain why it doesn't return any match with "m" flag while it returns exactly what it's expected with the "s" flag? |
|
#8
|
|||
|
|||
|
Quote:
I didn't say it would return a match using the MULTI_LINE flag ('m'). You just used the wrong terminology: the 's' is called the DOT-ALL flag which will let the DOT match line terminators as well (hence: DOT-ALL). |
|
#9
|
|||
|
|||
|
Quote:
Thanks, I always thought "s" was the newline since it does match newlines, but still I'd like to know why the "m" flag, in this case, doesn't return any match even though the string is multiline. |
|
#10
|
|||
|
|||
|
Quote:
When using the 'm' flag, the '^' not only matches the start of the entire input string, but also matches the beginning of each line in the string. And the '$' not only matches the end of the input string, but also the and of each line. Example input: Code:
12 34 56 78 90 00 Now let's say you want to match only the numbers that are at the end of each line, you can do: PHP Code:
which will produce the following output: Code:
Array
(
[0] => Array
(
[0] => 34
[1] => 78
[2] => 00
)
)
And when removing the 'm' flag in my example, you will see that only the "00" is matched. |
|
#11
|
|||
|
|||
|
Thanks!
|
|
#12
|
|||
|
|||
|
Quote:
You're welcome. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Regex Programming > 2nd pair of eyes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|