【发布时间】:2013-09-24 12:15:26
【问题描述】:
我在函数及其参数中遇到单引号和双引号问题。这是我的代码
$prev_page_arrow= "<span class='pagn_prev' onclick=\"send($where,'Page_{$this->name}=$prev&{$this->rppGet}{$this->query_string}#$this->anchor');\" >Prev</span>";
问题在于send 函数中的$where 参数。 $where 变量的值类似于
$where = purpose="buy" and city="cityname"
或
$where = purpose='buy' and city='cityname'
我可以在single 和double 引号中创建$where 属性值。问题是当值在double quotes 中时,它会结束函数参数。例如
$prev_page_arrow= "<span class='pagn_prev' onclick=\"send(purpose="buy",'Page_{$this->name}=$prev&{$this->rppGet}{$this->query_string}#$this->anchor');\" >Prev</span>";
这里引用的double 表示带参数的函数结束。同样,如果我使用single 引用,则表示参数结束。
如何解决?
【问题讨论】:
-
请避免以这种方式混合 HTML 和 PHP。使用“.addslashes($where)”。也许?
-
我的方法有什么解决方案吗? ;)
-
我编辑了第一条评论。基本上,由其他字符串变量组成的字符串变量也由另一个变量组成,这不是一个好主意。太乱了