Solved

Removing the ' and " marks

Posted on 2004-04-23
8
187 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
Comment Utility
0
 
LVL 6

Expert Comment

by:Lord_McFly
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
$data = addslashes($data)

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now