|
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]
|