栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在PHP中转义引号

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在PHP中转义引号

像这样使用反斜杠

"From time to "time"";

在PHP中,反斜杠用于转义引号内的特殊字符。由于PHP不能区分字符串和字符,因此您也可以使用

'From time to "time"';

单引号和双引号之间的区别在于,双引号允许对字符串进行插值,这意味着您可以在字符串中内联引用变量,并且它们的值将像在字符串中那样进行求值

$name = 'Chris';$greeting = "Hello my name is $name"; //equals "Hello my name is Chris"

根据您对问题的最后一次修改,我认为您可能能够做到的最简单的事情是使用“
heredoc”。它们并不常用,老实说,我通常不会推荐它,但是如果您想要一种快速的方法将文本墙放入单个字符串中,则不推荐使用。可以在以下位置找到语法:http
:
//www.php.net/manual/zh/language.types.string.php#language.types.string.syntax.heredoc,下面是一个示例:


$someVar = "hello";$someOtherVar = "goodbye";$heredoc = <<<termThis is a long line of text that include variables such as $someVarand additionally some other variable $someOtherVar. It also supports having'single quotes' and "double quotes" without terminating the string itself.heredocs have additional functionality that most likely falls outsidethe scope of what you aim to accomplish.term;


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/468776.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号