在PHP中,可以使用反斜杠(\)來轉義特殊字符。以下是一些常見的轉義字符的示例:
$str = "This is a \"quoted\" string.";
echo $str; // 輸出:This is a "quoted" string.
$str = 'This is a \'quoted\' string.';
echo $str; // 輸出:This is a 'quoted' string.
$str = "This is a \\ backslash.";
echo $str; // 輸出:This is a \ backslash.
$str = "This is a line of text.\nThis is a new line.";
echo $str; // 輸出:
// This is a line of text.
// This is a new line.
$str = "This is a tabbed\ttext.";
echo $str; // 輸出:This is a tabbed text.
需要注意的是,在使用某些特殊字符時,還需要考慮字符串的引號使用,避免引號的沖突。