修复代码php mysql

时间:2011-03-29 09:53:51

标签: php mysql

  

可能重复:
  PHP: Cannot assign string value to variable

if($page_name == "home"){
$header_text = "<a href="http://www.mysite.com/d">. $category .</a>";
}

如何解决它

4 个答案:

答案 0 :(得分:1)

首先回显$header_text = "<a href="http://www.mysite.com/d">. $category .</a>";

然后尝试回应$header_text = "<a href=\"http://www.mysite.com/d\"> $category </a>";

$header_text = '<a href="http://www.mysite.com/d">'. $category .'</a>';

请注意,在第一种情况下,您有错误,并且您将无法获得结果。

答案 1 :(得分:1)

尝试

if($page_name == "home"){
    $header_text = '<a href="http://www.mysite.com/d">'. $category .'</a>';
}

答案 2 :(得分:1)

if($page_name == "home") {
    $header_text = "<a href=\"http://www.mysite.com/d\">. $category .</a>";
}

你需要逃避你的报价。任何时候你想要一个也具有象征意义的角色,它需要被转义才能使用它的字面含义。

在此处阅读有关转义序列的更多信息: http://en.wikipedia.org/wiki/Escape_character

答案 3 :(得分:1)

检查以下代码:

if($page_name=="home")
{
   $header_text = '<a href="http://www.mysite.com/d">'. $category .'</a>';
   // Or,  $header_text = "<a href='http://www.mysite.com/d'>$category</a>";
}
相关问题