我怎样才能用很多双引号和单引号混合的字符串:
curl -A 'Curl/2.5' -d '{"key":"$api_key","message":{"html":"<p><h1>Hello World</h1><\/p>"}'并创建一个字符串变量,如:
$curl_command = "curl -A 'Curl/2.5' -d '{"key":"$api_key","message":{"html":"<p><h1>Hello World</h1><\/p>"}'"而不返回“意外的错误”?我想避免更改原来的字符串。
发布于 2013-10-17 19:02:17
您可以使用本文档语法和转义所有引号和双引号很容易。
这是它的语法。http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
注意,不要在heredoc标识符之前留出空间。
发布于 2013-10-17 19:02:29
利用HEREDOC语法。
<?php
$api_key='xx2233';
$content=<<<EOD
curl -A 'Curl/2.5' -d '{"key":"$api_key","message":{"html":"<p><h1>Hello World</h1><\/p>"}'
EOD;
echo $curlCommand=$content;输出:
curl -A 'Curl/2.5‘-d '{"key":"xx2233","message":{"html":“Hello”
发布于 2013-10-17 19:03:26
您可以使用Heredoc:
$string = <<<someStringYouWillAlsoNeedToStop
curl -A 'Curl/2.5' -d '{"key":"$api_key","message":{"html":"<p><h1>Hello World</h1><\/p>"}'
someStringYouWillAlsoNeedToStop; // this ends your string注意,这里的文档确实解析了您的$variables。如果您不想这样做,您应该在第一个someStringYouWillNeedToStop周围使用单引号来使用Nowdoc:
$string = <<<'someStringYouWillAlsoNeedToStop'
curl -A 'Curl/2.5' -d '{"key":"$api_key","message":{"html":"<p><h1>Hello World</h1><\/p>"}'
someStringYouWillAlsoNeedToStop; // this ends your stringhttps://stackoverflow.com/questions/19434948
复制相似问题