我刚刚遇到一个用于向用户显示错误消息的函数,其中有一部分我不明白。这里是函数的 ID。
public function display(){
echo "<div class=\"flash " . $this->type . "\">". $this->$msg ."</div>";
}
有人可以向我解释这里的目的"\"
是什么吗?
我刚刚遇到一个用于向用户显示错误消息的函数,其中有一部分我不明白。这里是函数的 ID。
public function display(){
echo "<div class=\"flash " . $this->type . "\">". $this->$msg ."</div>";
}
有人可以向我解释这里的目的"\"
是什么吗?
\ 是一个转义字符。它用于确保显示其他双引号内的双引号"。另一种编写方式是:
public function display(){
echo '<div class="flash ' . $this->type . '">'. $this->$msg .'</div>';
}
我认为上面的内容更具可读性。每当我需要实际输出双引号时,我将其放在单引号字符串中。但是,您需要阅读 PHP 中的单引号字符串和双引号字符串之间的差异:http://www.php.net/manual/en/language.types.string.php#language。 types.string.syntax.double
正如弗雷德所说,它是一个转义字符,允许您将字符作为引号等。