regex change me the result of preg_replace_callback

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Locked
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

regex change me the result of preg_replace_callback

Post 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>
:?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

This doesn't need a separate thread. Locked.
Locked