Rambo
Rambo

Reputation: 39

PHP : escape sequence for #

My program consist of single, double quotes and a hash function. Since # is a comment in PHP, I am not able to use it in my program. I have tried using the single quotes but still couldnt get it .

" class='inline' href='javascript:getlightboxcontent("#inline_content");' style='text-decoration:none;'>" 

Upvotes: 0

Views: 47

Answers (1)

rid
rid

Reputation: 63492

You don't need to escape # characters in order to create a string in PHP. Inside double quoted strings, you need to escape double quotes with a \ character. Example:

$string = "abc \"def\" ghi";

The value of $string in the above example will be:

abc "def" ghi

In your case, if your string is:

" class='inline' href='javascript:getlightboxcontent("#inline_content");' style='text-decoration:none;'>"

then you can use something like this:

" class='inline' href='javascript:getlightboxcontent(\"#inline_content\");' style='text-decoration:none;'>"

or, if you don't want to use single quotes for HTML attribute values, you could also use something like this:

" class=\"inline\" href=\"javascript:getlightboxcontent('#inline_content');\" style=\"text-decoration:none;\">"

Upvotes: 1

Related Questions