Forum Moderators: coopster

Message Too Old, No Replies

Quick way to escape quotes.

         

inveni0

9:57 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



Hey, I've got a big fat bunch of code I have to echo into a page using PHP. Is there a quick way to escape the quote, without having to go through it all manually?

jatar_k

9:59 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



addslashes [php.net] might work

coopster

10:00 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



htmlentities [php.net] won't work?

inveni0

10:12 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



Neither of those works because the quotes screw up the code. For instance, how could I echo:

<span class="style13"><b><font face="Arial, Helvetica, sans-serif" size="2">This forum Rocks</font><font face="Arial, Helvetica, sans-serif" size="2"> </font></b></span> </p>
<p align="center">

Without having to manually escape each character?

jatar_k

10:22 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



enclose it in single quotes if there are no single quotes in the string to be echo'ed

you should be able to just echo it straight up, where is it coming from?

coopster

10:30 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Oh, you meant echo the HTML into a page using PHP.

You could use jk's method of enclosing it in single quotes but if there are any single quotation marks you will have issues. Another option is heredoc syntax.

Strings [php.net]

inveni0

10:33 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



Well, that's the thing. There are single quotes in the code. This is a "POD" like hunk of code used on a client's page. I'm programming so that it may or may not be displayed, depending on the contents of a database table.

vevs

3:17 pm on Jan 18, 2006 (gmt 0)

10+ Year Member



how about to preg_replace all the " with \" and then use
echo "$string";

Vevs

inveni0

4:23 pm on Jan 18, 2006 (gmt 0)

10+ Year Member



No, that doesn't work. I think it's impossible (unless maybe there is some way to include the information from an external text file). I was just wondering for future reference. I've already gone through and escaped them all manually.... :(

coopster

4:52 pm on Jan 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So I take it you didn't read about the heredoc syntax noted earlier?

mooger35

10:19 pm on Jan 18, 2006 (gmt 0)

10+ Year Member



if you just want to replace the quotes, copy the code to notepad, hit ctrl-h and replace " with '.

IamStang

3:41 am on Jan 19, 2006 (gmt 0)

10+ Year Member



Not sure how much more involved your code is but I have used something like this in the past.

if($something == true){
?>

<span class="style13"><b><font face="Arial, Helvetica, sans-serif" size="2">This forum Rocks</font><font face="Arial, Helvetica, sans-serif" size="2"> </font></b></span> </p>
<p align="center">
<?
}

Maybe I am over looking something in your post and you need something more advanced, if so, just ignore me. LOL. It's late. I'm tired. I am not as alert as I could be. Ya know!