echo-php中的分号
我有这样的代码:echo-php中的分号,php,Php,我有这样的代码: <?php echo '<a onclick="function(''.$some.'');">'; ?> <a onclick="function('some');"> 我建议您在开始和结束php标记中编写此变量 <?php $some = "some"; ?> <a onclick="function('<?php echo $some; ?>');">Click me</a>
<?php
echo '<a onclick="function(''.$some.'');">';
?>
<a onclick="function('some');">
我建议您在开始和结束php标记中编写此变量
<?php $some = "some"; ?>
<a onclick="function('<?php echo $some; ?>');">Click me</a>
由于使用单引号引用字符串,因此必须在字符串中转义它们
只需在字符串中的每个引号前添加反斜杠\
:
<?php
echo '<a onclick="function(\''.$some.'\');"';
?>
不完全确定您需要什么信息,但这里有一个概述
在php中使用echo
ing时,可以同时使用单引号和双引号
echo "Some text to echo"; // Some text to echo
或
如果要回显用于封装字符串的引号类型,请像
echo "Some text with an \"escaped\" quote"; // Some text with an "escaped" quote
双引号内的字符串将接受一个内联变量
$var = "variable";
echo "A string with a $var in it"; // A string with a variable in it
而单引号中的字符串需要与变量关联
$var = 'variable';
echo 'A string with a '.$var.' in it'; // A string with a variable in it
查看完整的细节和示例。只需正确转义引号:echo”“代码>如果echo使用的是”
而不是“
”,或者只是执行
echo "Some text with an \"escaped\" quote"; // Some text with an "escaped" quote
$var = "variable";
echo "A string with a $var in it"; // A string with a variable in it
$var = 'variable';
echo 'A string with a '.$var.' in it'; // A string with a variable in it