Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output a string with a double quotation mark?

Tags:

php

quotes

I need to output a string, which is basically a java code:

I have something like this:

$web = "...if (url.contains('.mp4'))..."

I need that the single quotation mark, will be a double one, and not in html code.

Is it possible to do it?

like image 571
Itai Sagi Avatar asked May 29 '11 14:05

Itai Sagi


People also ask

How do you display double quotes in a string?

The basic double-quoted string is a series of characters surrounded by double quotes. If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters.

How do you print double quotes in output?

\" - escape sequence Since printf uses ""(double quotes) to identify starting and ending point of a message, we need to use \" escape sequence to print the double quotes.


3 Answers

$new_str = str_replace('\'', '"', $web);

You could optional do it by modifying the actual string (note the use of \ to escape the quotation marks):

$web = "...if (url.contains(\".mp4\"))..."
like image 51
Tim Cooper Avatar answered Sep 27 '22 15:09

Tim Cooper


You can use like this

$web = "...if (url.contains(\".mp4\"))...";
like image 39
Xuvi Avatar answered Sep 27 '22 15:09

Xuvi


Short of doing a strtr() replacement, just escape your double quotes:

$web = "...if (url.contains(\".mp4\"))..."

See http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double for the complete list of escaping rules.

like image 45
mario Avatar answered Sep 27 '22 17:09

mario