Posted by naixn on 12/09/06 19:49
BKDotCom wrote :
> emmerink@gmail.com wrote:
>> $xml = "tekst <title> twee </title>\n drie </tr> vier </td>";
>>
>> $a_sSubject = trim($xml);
>>
>> $a_sStart = '<title>';$a_sEnd = '<\/tr>';
>> $pattern = '/'. $a_sStart .'(.*?)'. $a_sEnd .'/';
>> preg_match_all($pattern, $a_sSubject, $result);
>>
>> print_r($result);
>>
>> Any idea why there is no content in the result?
>> (expected to find the content in between <title> en </tr>)
>
> pay no attention to naixn. :) The ? character != "ignore" it means
> "not greedy"
> Your "problem" is that your search string contains a linebreak.
> you need to add the "s" modifier to your expression so that the "."
> matches the "\n"
> http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php
> $pattern = '/'. $a_sStart .'(.*?)'. $a_sEnd .'/s'; // should be good
>
I didn't say that ? == 'ignore', but 0 or 1 :p
But I didn't know it was able to manage greediness. I learnt some more regexp
today =D. Thanks ;)
--
Naixn
http://fma-fr.net
Navigation:
[Reply to this message]
|