You are here: Help with preg_replace « PHP « IT news, forums, messages
Help with preg_replace

Posted by Marcos Mendonηa on 09/28/07 11:20

Hi list

I need help to solve a preg_replace() problem.

I have a snippet of html code that contains some links.

I have an array thats contains all links inside that snippet of html code.

What i need to do is replace all the links in the code by another on.

So this is what iΒ΄m trying to do:

//links that should be replaced
$url = array(
array("id" => 0, "url" => "http://www.silika.com.br/conarh/mala3"),
array("id" => 1, "url" => "http://www.conarh.com.br"),
array("id" => 2, "url" =>
"http://www.conarh.com.br/main_frameset.php?secao=congresso&idioma=port&pagina=http://www.conarh.com.br/programacao/pub/index.php?tipo_barra=laranja"),
array("id" => 3, "url" =>
"http://www.conarh.com.br/main_frameset.php?secao=congresso&idioma=port&pagina=http://www.conarh.com.br/mensagem/pub/mensagem.php?id_mensagem=insc_temp&tipo_barra=laranja"),
array("id" => 4, "url" =>
"http://www.silika.com.br/conarh/patrocinio/patrocinio.htm"));

$escape_chars = array("?", "/");
$escaped_chars = array("\?", "\/");

$matches = array();

foreach ($url as $link) {
$pattern = "/" . str_replace($escape_chars, $escaped_chars, $link["url"]) ."/";
$newurl = URL_LINKS."linkId=".$link["id"]."&rId=1";
$body_html = preg_replace($pattern, $newurl, $body_html, 1);
}

This works fine for links with id 0, 1 and 4. But i havenΒ΄t been able
to figure out how to match and replace links with id 2 and 3.

How do I get my regex to match and replace those links as well? Any
help appreciated.

Thanks.

 

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация