2016-04-23 13:37
浏览 101

分号在echo php中

i have code like this :

    echo '<a onclick="function(''.$some.'');">';

how can it return html like this :

 <a onclick="function('some');">

Big Thanks

图片转代码服务由CSDN问答提供 功能建议


 echo'&lt; a onclick =“function(''。some some。'');”&gt;'; 

如何 可以像这样返回html:

 &lt; a onclick =“function('some');”&gt; 
 \  n 


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongwen1871 2016-04-23 13:48

    Since you quoted the string with single quotes, you have to escape them inside the string.

    Simply add a backslash \ before each single quote inside the string:

        echo '<a onclick="function(\''.$some.'\');"';

    Also you can do that in a few other ways like:

    echo "<a onclick=\"function('{$some}');\""; 

    Double quotes lets you simply embed a variable instead of concating, but now you have to escape double quotes.

    打赏 评论
  • dpg98445 2016-04-23 13:48

    I'd suggest you to write this variable within an opening and closing php tag.

    <?php $some = "some"; ?>
    <a onclick="function('<?php echo $some; ?>');">Click me</a>

    This generates:

    <a onclick="function('some');">Click me</a>
    打赏 评论
  • doudaiyao0934 2016-04-23 13:56

    Not entirely sure what information you need but here's an overview...

    You can use both single and double quotes when echoing in php,

    echo "Some text to echo"; // Some text to echo


    echo 'Some text to echo'; // Some text to echo

    If you want to echo the quote type used to encapsulate the string, escape it like,

     echo "Some text with an \"escaped\" quote"; // Some text with an "escaped" quote

    Strings within double quotes will accept a variable inline,

    $var = "variable";
    echo "A string with a $var in it"; // A string with a variable in it

    Whereas strings within single quotes need to be concatinated with variables,

    $var = 'variable';
    echo 'A string with a '.$var.' in it'; // A string with a variable in it

    Check out for full details and examples.

    打赏 评论

相关推荐 更多相似问题