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

Posted by emmerink on 12/09/06 17:24

BKDotCom schreef:

> 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

Thanks, that did it. Although naixn noticed the modifier, you were
much more to the point (which made it more useful in this quite
confusing regexp notations).

 

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

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