How to output a string with a double quotation mark?

老子叫甜甜 提交于 2019-12-08 19:21:38

问题


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?


回答1:


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



回答2:


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.




回答3:


You can use like this

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



回答4:


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



来源:https://stackoverflow.com/questions/6168298/how-to-output-a-string-with-a-double-quotation-mark

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!