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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

then you'll want..

 

$getname = $_GET["name"];
$name = str_replace(" "."'",$getname);

 

will replace the space in the string with an apostrophe

 

I know, but doesnt it replace the space too, it will output Papa's'Home instead of Papa's Home?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.