您正在制作一个声明,您自己在其中声明换行符。所以你的变量包含换行符,因为你把它们放在那里。现在你有两个选择:
1:不要放入换行符
$sql = "UPDATE `key_values` SET ".
"`Value_Content` = '" . $this->db->escape($revisionValues['value']) . "', ".
"`Comments` = '" . $this->db->escape($revisionValues['comment']) . "', ".
"`Is_Active` = '" . $this->db->escape($revisionValues['actstate']) . "', ".
"`Is_Modified`='1' ".
"WHERE ".
"`Key_Value`='" . $candidateKey['key'] . "' ".
"AND `Email_Template`='" . $candidateKey['template'] . "' ".
"AND `Locale_ID`='" . $candidateKey['locale'] . "'";
2:删除后
$sql = "UPDATE `key_values` SET
`Value_Content` = '" . $this->db->escape($revisionValues['value']) . "',
`Comments` = '" . $this->db->escape($revisionValues['comment']) . "',
`Is_Active` = '" . $this->db->escape($revisionValues['actstate']) . "',
`Is_Modified`='1'
WHERE
`Key_Value`='" . $candidateKey['key'] . "'
AND `Email_Template`='" . $candidateKey['template'] . "'
AND `Locale_ID`='" . $candidateKey['locale'] . "'";
$sql = str_replace(array(chr(10), chr(13)), '', $sql);
所以检测一个换行符是检查 chr(10) 或 chr(13)。根据您使用的系统,可能是其中之一,也可能是两者。请参阅:换行符 = \n 还是 \r\n? ( \r=chr(13)
& \n=chr(10)
)
更新
如果要从 token_get_all() 返回单行字符串,可以使用:
<?php
$c = str_replace(array("\n","\r"), '', print_r(token_get_all('<?php echo; ?>'), true));
print $c;
// token_get_all() returns an array
// print_r(array, true) prints the array and the true param makes it return the output as a string
// replace the newline chars with nothing to make it single line
//single line output:
//Array( [0] => Array ( [0] => 372 [1] => 1 ) [1] => Array ( [0] => 316 [1] => echo [2] => 1 ) [2] => ; [3] => Array ( [0] => 375 [1] => [2] => 1 ) [4] => Array ( [0] => 374 [1] => ?> [2] => 1 ))
?>