使用 Python 的三引号字符串,我可以定义包含'
、反引号的字符串,或者"
不必关心它:
hello = """
This string is bounded by triple double quotes (3 times ").
Unescaped newlines in the string are retained, though
it is still possible to use all normal escape sequences.
Whitespace at the beginning of a line is
significant.
This string ends in a newline.
"""
在 PHP 中,我可以使用heredoc ( <<<
):
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
我怎样才能在 MySQL 中做同样的事情?现在我必须确保我转义了我用来分隔的字符,例如,如果我'
用作分隔符,我必须\'
在我的字符串中使用:
UPDATE article
SET article_text ='
Extra-virgin olive oil is a staple in any chef\'s kitchen.
'
我希望能够像
UPDATE article
SET article_text ='''
Extra-virgin olive oil is a staple in any chef's kitchen.
'''