Removing the ' and " marks

Hi all,

     I want to store some html/php/javascript in a mySQL database field i.e.

<?php echo "hello" ?>

and then extract this information and echo it via a php script. i.e.

//conect to db

$info = mysql_query("select * from script where script_id = $script_id", $db);

//if entry exists

echo "$info";

The problem is that the script contains "speech marks" and ultimately ends the echo " " function to early. Any ideas?

-Thanks Chris.
Who is Participating?
Before performing the insert do something like..

mysql_query = Replace(mysqlquery,Chr(34),"[quote]")

..then do you insert / update

The just do the reverse Replace when you extract..

myString = Replace(rs("FieldName"),"[quote]",Chr(34))

I can't remember the Chr() num,ber for quotes so just check that out.
I was just going over my posts again and realised my suggestion wasn't relavent as you're using php :)

I'm guessing that you are getting a prepared php scripted and just want to display it with your webpage - I think the following might work - replace " with the HTML equiv.

$info = str_replace(chr(34),'&quot;',$info)
Why not remove the quotes around $info like so:
echo $info;

Not sure why having quotes around it should break it though.  Also, beware of SQL injection in your select statement:

if(is_numeric($script_id)) {
   $info = mysql_query("select * from script where script_id = $script_id", $db);
$data = addslashes($data)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.