apostrophe into string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

apostrophe into string

Post by sarris »

hi there...
super simple question for most of you out there,
i am having a php string define by ' (ex. 'this is my string') and i want to have the ' characted into the string. (ex. 'this is 'my' string' )
how can i do that? something about the / character or that works only at javascript?
thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

$s = "this is 'my' string";
$s = 'this is \'my\' string';
$s = <<< eot
this is 'my' string
eot;
make your choice.
.Stealth
Forum Commoner
Posts: 57
Joined: Wed Jan 10, 2007 12:15 pm
Location: Manchester, England

Post by .Stealth »

In my opinion the EOT method is probably best but does complicate things alot if you dont know how to use it.

http://www.php.net/heredoc

That explains it, using that you don't need to escape any " double quotes or single quotes etc.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Simplest thing to do is escape characters that need escaping. Output is not the only time you would use escaping, so it should come naturally.
Post Reply