所以,我正在尝试将一个变量(带空格的字符串)发布到另一个php文件。
该变量包含SQL请求的一部分WHERE Row = 'something'
。
如果我在我的变量周围添加单引号,那么它显然会引发错误,因为它并不期望'某些东西'。但是,如果我使用双引号,那么单引号会引用“'也被改为双引号。我怎样才能发布这个字符串?
function getAJAXlink( $count, $text) {
if (!empty($this->sqlVariable)) {
$addVarToLink = ", 'sqlVariable': '".$this->sqlVariable."' ";
}
if( $this->contentDiv == '')
return '<a href="'. $this->anchorClass . ' ' . $this->baseURL . $count . '">'. $text .'</a>';
$pageCount = $count?$count:0;
$this->additionalParam = "{ 'page' : $pageCount $addVarToLink}";
return "<a href=\"javascript:void(0);\" " . $this->anchorClass . "
onclick=\"$.post('". $this->baseURL."', ". $this->additionalParam .", function(data){
$('#". $this->contentDiv . "').html(data); }); return false;\">"
. $text .'</a>';
}
function getAJAXlink( $count, $text) {
if (!empty($this->sqlVariable)) {
$addVarToLink = ", 'sqlVariable': \"".$this->sqlVariable."\" ";
}
if( $this->contentDiv == '')
return '<a href="'. $this->anchorClass . ' ' . $this->baseURL . $count . '">'. $text .'</a>';
$pageCount = $count?$count:0;
$this->additionalParam = "{ 'page' : $pageCount $addVarToLink}";
return "<a href=\"javascript:void(0);\" " . $this->anchorClass . "
onclick=\"$.post('". $this->baseURL."', ". $this->additionalParam .", function(data){
$('#". $this->contentDiv . "').html(data); }); return false;\">"
. $text .'</a>';
}
答案 0 :(得分:0)
自己找到答案。下面是工作代码:
function getAJAXlink( $count, $text) {
if (!empty($this->sqlVariable)) {
$addVarToLink = ", 'sqlVariable': "".$this->sqlVariable."" ";
}
if( $this->contentDiv == '')
return '<a href="'. $this->anchorClass . ' ' . $this->baseURL . $count . '">'. $text .'</a>';
$pageCount = $count?$count:0;
$this->additionalParam = "{ 'page' : $pageCount $addVarToLink}";
return "<a href=\"javascript:void(0);\" " . $this->anchorClass . "
onclick=\"$.post('". $this->baseURL."', ". $this->additionalParam .", function(data){
$('#". $this->contentDiv . "').html(data); }); return false;\">"
. $text .'</a>';
}