Jump to content

Add a quote to a string


Cyto

Recommended Posts

escape the quotes.

$string = "Papa\'s Home";

 

in this situation, you actually wouldn't have to, because I used double quotes on the outside, and a single quote inside, but if you're planning on putting this into a database you'll definitely need to escape your strings properly. look up mysql_real_escape_string, addslashes and stuff like that.

 

good luck

escape the quotes.

$string = "Papa\'s Home";

 

if you test this, it actually won't work while the string is encased in double quotes...this will only work if it is encased in single quotes...double quotes are mainly used to escape special characters..however characters that do not need to be escaped will display the backslash as well...

 

@AyKay47 lol, it's like I'm following you! :P

:P

escape the quotes.

$string = "Papa\'s Home";

 

in this situation, you actually wouldn't have to, because I used double quotes on the outside, and a single quote inside, but if you're planning on putting this into a database you'll definitely need to escape your strings properly. look up mysql_real_escape_string, addslashes and stuff like that.

 

good luck

 

Another problem that I'm having:

I want to get ($_GET) the name like this: Papa's, so i can get the result from the database..

The url: http://www.link.com/papa-s-home/

but i need to have papa's home with a quote to get a match from the database. So i need to add a quote at the empty spot Papa s, but how can i do this. My part of the code:

 

$getname = $_GET["name"];
$cleanname = array("-","/");
$name=mysql_real_escape_string(str_replace($cleanname," ",$getname));

 

I hope you'll understand it, sorry for my english :D

okay so you'll use something like

 

	$getname = $_GET["name"];
$cleanname = array("-","/");
$name = str_replace($cleanname,"'",$getname);

 

$name should output papa's

 

of course it will work, except you need to add stripslashes when echoing it:

 

echo stripslashes($string);

 

:P

ew.. :P

 

 

Note: you can actually write it like this as well...

 

$string = "Papa's";

okay so you'll use something like

 

	$getname = $_GET["name"];
$cleanname = array("-","/");
$name = str_replace($cleanname,"'",$getname);

 

$name should output papa's

 

This works if the result were all with quotes, but it isn't. Then the names without a quote wouldn't work. I'm already adding the names with stripslashes. The name is already Papa's Home in the database. But I when i go to this link http://www.link.com/papa-s-home/, it querys papa s home. I need to add a quote somehow to strings like papa s, mama s etc. To get a result from the database.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.