Reply to Re: strange behaviour: preg_replace with /e modifier and str_replace

Your name:

Reply:


Posted by Schraalhans Keukenmeester on 05/28/07 08:29

At Mon, 28 May 2007 08:18:14 +0200, amygdala let h(is|er) monkeys type:

> 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 replaceSingleQuotesInsideTags( $input )
> {
> $output = preg_replace(
> '/<[^>]*>/e',
> "str_replace( '\'', '\"', '$0' )",
> $input
> );
> return $output;
> }
>
> So let's say I have this string of HTML code:
>
> On <A href="/home/" target="_self">this</A> page you will find <SPAN
> STYLE='font-style: italic'>stuff</SPAN>
>
> Result:
> On <A href=\"/home/\" target=\"_self\">this</A> page you will find <SPAN
> STYLE="font-style: italic">stuff</SPAN>
>
Quoted verbatim from the preg_replace manual section:

When using the e modifier, this function escapes some characters
(namely ', ", \ and NULL) in the strings that replace the
backreferences. This is done to ensure that no syntax errors arise
from backreference usage with either single or double quotes (e.g.
'strlen(\'$1\')+strlen("$2")'). Make sure you are aware of PHP's
string syntax to know exactly how the interpreted string will look
like.

Seems a stripslashes to finish up is what you need.
Regards,

--
Schraalhans Keukenmeester - schraalhans@the.spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]
"strcmp('apples','oranges') is -1"

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация