Solved

Removing the ' and " marks

Posted on 2004-04-23
8
191 Views
Last Modified: 2010-04-06
Hi all,

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

<html>
<p>
<?php echo "hello" ?>
</p>
</html>


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.
0
Comment
Question by:icb01co2
8 Comments
 
LVL 6

Accepted Solution

by:
jkna_gunn earned 55 total points
ID: 10898177
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10898692
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.
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10946127
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)
0
 
LVL 8

Expert Comment

by:hendridm
ID: 10959422
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);
}
0
 

Expert Comment

by:zeroisawuss
ID: 11008517
$data = addslashes($data)

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
My first jQuery plugin: is the right tutorial missing? 2 101
Clean URL from GET variables 2 113
Format results with PHP 3 79
removing a class in javascript 4 49
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa‚Ķ
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question