Forum Moderators: coopster

Message Too Old, No Replies

Help with preg_replace

Regex Question

         

discolando

9:29 pm on Jul 1, 2005 (gmt 0)

10+ Year Member


Hello all,

Could someone help me craft a regex to use in a preg_replace()?

What I need is a regex to escape all quotes that lie between every .?> and <? in a page. So, given:

<? ..?>
<form method="post">
<input type="text" name="text" />
<input type="submit" value="submit" />
</form>
<? ..?>

I need to replace that with:

<? ..?>
<form method=\"post\">
<input type=\"text\" name=\"text\" />
<input type=\"submit\" value=\"submit\" />
</form>
<? ..?>

Any help would be greatly appreciated!

bennymack

12:17 am on Jul 2, 2005 (gmt 0)

10+ Year Member



Looks like you will want to use some of the built object buffering functions in PHP.

Take a look at: [us2.php.net...]

I'm not sure if you HAVE to use the <? ..?> but it seems a little hackish. This is possibly the correct way to accomplish what
you're trying to do.

discolando

4:38 am on Jul 2, 2005 (gmt 0)

10+ Year Member



Hmmm... I'm not sure what you're getting at. Maybe we're not talking about the same thing. :)

Basically, all I need is a regex that will escape all quotes between every?> and <? that I can use in a preg_replace().

Any magicians out there?

henry0

12:35 pm on Jul 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can make your life easier by using heredoc syntax.
Then use HTML quotes.
with EOD you do not need to start and end a HTML block with " ".
but surround your block with EOD as follow:
<<<EOD
<div align="center">
<a href="qwert">aaaa</a>
etc.... and end it with
EOD;

Be sure that first and last EODs starts and ends on a new line.

if you are only looking about solving a quote problem that should do it.