You are here: Re: expression problem « PHP Programming Language « IT news, forums, messages
Re: expression problem

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация