Hi there,
I'm trying to replace single quoted attributes in HTML tags with double
quotes. What I've come up with is this:
function replaceSingleQu otesInsideTags( $input )
{
$output = preg_replace(
'/<[^>]*>/e',
"str_replac e( '\'', '\"', '$0' )",
$input
);
return $output;
}
So let's say I have this string of HTML code:
On <A href="/home/" target="_self"> this</Apage you will find <SPAN
STYLE='font-style: italic'>stuff</SPAN>
Result:
On <A href=\"/home/\" target=\"_self\ ">this</Apage you will find <SPAN
STYLE="font-style: italic">stuff</SPAN>
As you can see, when I run it through my function
replaceSingleQu otesInsideTags, not only does it replace the single quotes
with double quotes, but it also adds backslashes before double quotes that
were already present. This is unexpected behaviour to me.
Expected result:
On <A href="/home/" target="_self"> this</Apage you will find <SPAN
STYLE="font-style: italic">stuff</SPAN>
Note the missing backslashes in the anchor tag attributes.
Does anybody have an idea of what is going on here?
Working with PHP 5.1.4, magic_quotes (all) off.
Thank you in advance.
I'm trying to replace single quoted attributes in HTML tags with double
quotes. What I've come up with is this:
function replaceSingleQu otesInsideTags( $input )
{
$output = preg_replace(
'/<[^>]*>/e',
"str_replac e( '\'', '\"', '$0' )",
$input
);
return $output;
}
So let's say I have this string of HTML code:
On <A href="/home/" target="_self"> this</Apage you will find <SPAN
STYLE='font-style: italic'>stuff</SPAN>
Result:
On <A href=\"/home/\" target=\"_self\ ">this</Apage you will find <SPAN
STYLE="font-style: italic">stuff</SPAN>
As you can see, when I run it through my function
replaceSingleQu otesInsideTags, not only does it replace the single quotes
with double quotes, but it also adds backslashes before double quotes that
were already present. This is unexpected behaviour to me.
Expected result:
On <A href="/home/" target="_self"> this</Apage you will find <SPAN
STYLE="font-style: italic">stuff</SPAN>
Note the missing backslashes in the anchor tag attributes.
Does anybody have an idea of what is going on here?
Working with PHP 5.1.4, magic_quotes (all) off.
Thank you in advance.
Comment