开发者

How to output a string with a double quotation mark?

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 q开发者_如何学Cuotation mark, will be a double one, and not in html code.

Is it possible to do it?


$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\"))..."


You can use like this

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


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.


You should use this

<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;
?>

see http://docs.php.net/manual/en/function.htmlspecialchars.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜