Page 1 of 1

regex change me the result of preg_replace_callback

Posted: Sat Oct 28, 2006 11:29 am
by visonardo
for example

Code: Select all

$a2="    <a href=http://holaaaa something=value>      <link href=' hola che!' boder> ";

function change($aver)
{
return strtoupper($aver[0]);
}

echo preg_replace_callback("/[a]*/is","change",$a2);
It work perfectly, but....


Code: Select all

$a2="    <a href=http://holaaaa something=value>      <link href=' hola che!' boder> ";

function ech($aver)
{
	if($aver[1]{0}!='\'' && $aver[1]{0}!='"')
		$av=str_replace($aver[1],'"'.$aver[1].'"',$aver[0]);
return $av;
}


$z2='/<\s*[a-z:-]+\s+.*?\s*href\s*=\s*(?:'.'([\'"`])(.*?)\\1|([^\s]+))[^>]*>/is';
echo preg_replace_callback($z2,"ech",$a2);
# The problem is that return me the last match like $a2´s content, and not all content with some changes. Why? 8O

This last print me that $a2´s content is

Code: Select all

<link href=' hola che!' boder>
and not

Code: Select all

<a href="http://holaaaa" something=value>      <link href=' hola che!' boder>
:?

Posted: Sat Oct 28, 2006 3:38 pm
by feyd
This doesn't need a separate thread. Locked.