我在函數及其參數中存在單引號和雙引號問題。這裏是我的代碼在php中使用單引號引起的問題
$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"
OR
$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)」。也許? –
我有沒有解決方法? ;) –
我編輯了第一條評論。基本上,創建由其他字符串變量構成的字符串變量並不是一個好主意,其他字符串變量也由其他變量組成。太髒了 –