Page 1 of 1

apostrophe into string

Posted: Fri Jun 22, 2007 6:40 pm
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

Posted: Fri Jun 22, 2007 6:55 pm
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.

Posted: Fri Jun 22, 2007 7:02 pm
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.

Posted: Fri Jun 22, 2007 7:22 pm
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.