|
Posted by naixn on 12/09/06 11:11
emmerink@gmail.com wrote :
> Hi,
>
> $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);
>
>
>
> results in:
> Array
> (
> [0] => Array
> (
> )
>
> [1] => Array
> (
> )
>
> )
>
> Any idea why there is no content in the result?
> (expected to find the content in between <title> en </tr>)
>
> Thanks for any help.
>
Why use (.*?) ?
That means : search for any string with 0 or more characters. And the
'?' is here to say 'but this is not mandatory'.
That means : 0 ore more characters, or 0 characters.
Now:
<?php
$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);
?>
That worked for me (using '!' instead of '/' as regexp delimiter).
You may try to play 's' and/or 'm' regexp modifier to match the newline
character.
--
Naixn
http://fma-fr.net
[Back to original message]
|