You are here: Re: Why doesn't preg_replace work? « PHP Programming Language « IT news, forums, messages
Re: Why doesn't preg_replace work?

Posted by Gilles Ganault on 05/08/07 00:17

On 7 May 2007 16:46:27 -0700, klenwell <klenwell@gmail.com> wrote:
>2. smiU - That's modifier overkill. The U here and the ? in your
>expression are probably reacting to each other in unexpected ways.

Ah, ah... Indeed, it seems like it's either using the U switch to make
Preg non-greedy, or use the ? limiter (eg. ".+?"). Thanks for pointing
it out.

Found it: To extract bits, I shouldn't use preg_replace() but
preg_match():

--------------
$url = "http://www.cnn.com";
$response = file_get_contents($url);

preg_match("|<title>(.+?)</title>|smi",$response,$matches);
$response = $matches[1];

$fp = fopen ("output.html", "w");
fputs ($fp,$response);
fclose($fp);
--------------

Thank you.

 

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

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