Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"" in url string 3

Status
Not open for further replies.
Before displaying the url, run the variable through addslashes()


Calvin

 
Or better yet, try urlencode($variable); This is the official "right" way to handle it. Even better yet, read the following web page carefully:
 
Sure, use the addslashes() function in PHP.

First, test if the value is a string:

[tt]
if (is_string($value) {
// if its a string, add the slashes
addslashes($value);
print $value;
} else {
// don't add slashes and print it normally
}
[/tt]

Hope this helps.

-Vic
vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
thanx alot

problem solved! ######## CtN ########
 
PROBLEM NOT SOLVED.

I thought it worked but it didn't.

I'm getting the string from a db now and nothing seems to work.

I've tried addshlashes, urlencode, rawurlencode, urldecode, rawurldecode.

How can I get these freakin' ""'s to display???

Please help ######## CtN ########
 
Did the string use to work with the database before? If it did, you can always use stripslashes() to undo what you did with addslashes() before querying the database.

Could you provide more information on the problem, like what error messages are you getting if any? What you are trying to do, etc?


Calvin
 
Hi,

I have in a db field:

desc=17mm(3"")nails

The output I get:

17mm(3
How do I display the "" ??

I've tried addshlashes and some other stuff, but nothing seems to work.

thanx ######## CtN ########
 
OK, try this simple test script:

Code:
<html>
<body>
<?php
$string = urlencode('17mm(3&quot;&quot;)nails');
echo &quot;<a href=\&quot;$PHP_SELF?desc=$string\&quot;>Test Link</a>&quot;;
?>
<br>
<br>
<?php
echo stripslashes($desc);
?>
</body>
</html>

Click on the link and see if your value is echoed back correctly. It works fine on my machine. If you do not have magic quotes enabled, you will not even need to use stripslashes() on the $desc variable.
 
Rycamor,

Your test script works fine, but still doesn't work from my script. the string I get from a db:

if($ID){
$connect = odbc_connect(&quot;LHCOS&quot;, &quot;lhcintranet&quot;, &quot;hoogwater&quot;);
$query = &quot;SELECT * FROM tblStationary WHERE ID=$ID&quot;;
$result = odbc_exec($connect, $query);


while(odbc_fetch_row($result)){
$sentdesc = (odbc_result($result, 2) == &quot;&quot;) ? &quot;----&quot; : odbc_result($result, 2);
$sentstock = (odbc_result($result, 3) == &quot;&quot;) ? &quot;----&quot; : odbc_result($result, 3);
$sentprice = (odbc_result($result, 4) == &quot;&quot;) ? &quot;----&quot; : odbc_result($result, 4);

}
---------------------------------------------------
$sentdesc holds the string containing the &quot;&quot;

what do you think??

thanx ######## CtN ########
 
Are you saying that when you simply try to echo or print() the $setdesc variable as HTML, you only get up to the first quote? I thought the problem here was in the URL query string. If the problem is in output from the database, that's another question.

If this does involve the URL query string, why on earth are you trying to pass a value like that on the query string in the first place? Why not just pass an ID, and pull the other values from the database at each page?

Do you know if the string is actually placed in the database right the first time? In other words, do we know if the problem is output, or is it possibly input?
 
dude,

It WAS passed with a query string. Now it IS only the ID that is passed.

I am reading this out of the db.

######## CtN ########
 
OK,

Let me rephrase:

I have in a database the field 'descc':
+-------------------+
+ 17mm(3&quot;&quot;)nails +
+-------------------+

I only want to query the db and display 17mm(3&quot;&quot;)nails.

but I get 17mm(3
thanx for your time ######## CtN ########
 
hi curvv

why dont u use

$str1 = eregi_replace(&quot;\\\&quot;&quot;,&quot;\&quot;&quot;,$str) ;
echo $str1 ;

where $str is the value coming from database.
hope that will help u

cheers

spookie
 
OK curvv,

Cool, I'm getting the picture now. So you are sure you have the data in the database, and you are calling it with ODBC, and you are using
Code:
echo $sentdesc;
to output it.

I think that the problem might be with ODBC, because it seems we have eliminated every other possibility. Is this an MSSQL database, or Access?

Check out this link:
You can always replace the quotes completely with the HTML Coded character set. Thus
Code:
17mm(3&quot;&quot;)nails
would be translated to
Code:
17mm(3&amp;#34;&amp;#34;)nails
. This will display as quotes in the browser, but in actual text view, the quotes are
Code:
&amp;#34;
.
 
Hi again.

I'm using access.

eregi_replace didn't change a thing.

thanx alot for your help.

I'm going to do a couple of tests to see how it works with mySQL and stuff.

Later

######## CtN ########
 
What do you mean eregi_replace didn't change a thing? Eregi_replace should have replaced all quotes, before inserting your string into the database, so now if you have a problem, it couldn't possibly be happening at the &quot; symbol.

By the way, if you were trying to replace the quotes with the HTML character code, you should have used str_replace() ( It's much faster.

(Again, none of this will work on a URL, because the # symbol breaks a query string. urlencode is the way to handle URLS)
 
The database is being populated by someone else somewhere else. I just need to retrieve the data. There must be some way to do this. Anyway I'll go have a look.

thanx ######## CtN ########
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top