condition?

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

Moderator: General Moderators

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

Post by visonardo »

sorry by insist but now i have a secundary problem :?

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 »

I'm having a tough time trying to figure out what you're trying to do... It looks like you want to add quotes around the url's that don't have them, in which case you'll be working with the third element of the array given to ech().
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Post by visonardo »

thank feyd :wink:
Post Reply