$html .= '<a onmouseout="document.getElementById('title').style.display='none'" onmouseover="document.getElementById('title').style.display='block'" href="http://www.google.com" target="_blank">'
$html .= 'Over me'
$html .= '</a>'报错:Parse error: syntax error, unexpected T_STRING
怎么写规范呢?

解决方案 »

  1.   

    <?php
    $html="<a onmouseout=document.getElementById('title').style.display='none' onmouseover=\"document.getElementById('title').style.display='block' href='\"http:\/\/www.google.com' target='_blank'>'";
    $html='Over me';
    $html='</a>';
    ?>
    说实话,没有完全看懂你要怎么写,不过可以给你提点我发现的问题
    第一、给一个变量赋值,不需要用“.”连接,如你的$html.='Over me',这个应该写成$html="Over me";
    第二、在php中插入html或者js代码,要尽量少用“"”,一般尽可能使用单引号,这样会减少你的麻烦,当然实在无法使用单引号,就得用双引号,但记住要用转义符“\”,如果用双引号就应该写成“\"”,这样可以合php中的双引号区别开来。
    第三、还是转义字符,如你输入网址,一定要写成“http:\/\/www.……”,这样的格式就不会报错了
      

  2.   

    caofei277你好,我想要的是鼠标移动到文字上显示DIV,离开隐藏DIV。你的代码在Firefox的firebug里显示为,不知道什么原因。
    <a target="_blank" www.google.com="" \="" http:\="" onmouseover="document.getElementById('title').style.display='block' href='" onmouseout="document.getElementById('title').style.display='none'">Over me</a>
      

  3.   

    这个问题通过我自己修改,现在在Firefox源文件里显示正确了:$html='<a onmouseout="document.getElementById(\'title\').style.display=\'none\'" onmouseover="document.getElementById(\'title\').style.display=\'block\'" href="http:\/\/www.google.com" target="_blank">';
    $html='Over me';
    $html='</a>';请高手们再帮我检查一下,这样对不对?
      

  4.   

    #3 的写法显然是不对的
    在连续的对 $html 赋值后,$html 的值为 </a>最好写作
    $html =<<< HTML
    <a onmouseout="document.getElementById('title').style.display='none'" 
    onmouseover="document.getElementById('title').style.display='block'"
    href="http://www.google.com" target="_blank">Over me</a>
    HTML;
      

  5.   

    感谢caofei277和xuzuning。现在我明白了。