我正在尝试将数据输出到图表,但我在preg_replace statment上收到此错误。
ImageTTFText($this->img, $which_font['size'], $which_angle,
$which_xpos, $which_ypos, $which_color, $which_font['font'], $which_text);
}
// Fixed fonts:
else {
// explode the text by its lines, and count them
$which_text = preg_replace("\r", "", $which_text);
$str = explode("\n", $which_text);
$nlines = count($str);
$spacing = $this->line_spacing * ($nlines - 1);
答案 0 :(得分:5)
您的正则表达式\r
无效;您必须有一个开始/停止分隔符(例如,/
)。尝试将其更改为/\r/
:
$which_text = preg_replace("/\r/", "", $which_text);
答案 1 :(得分:2)
您对preg_replace
使用了错误的语法。
您的字符串替换将使用简单的str_replace
函数正常工作:
$which_text = str_replace("\r", "", $which_text);
preg_replace
旨在用于匹配复杂模式,例如 任意字后跟空格。
如果您想要替换已知的确切子字符串,则必须改为使用str_replace
。