警告:preg_replace() [function.preg-replace]:C:xampp 中的空正则表达式



我正在尝试将数据输出到图形,但我在语句preg_replace收到此错误。

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);

正则表达式是无效的r;您必须有一个开始/停止分隔符(例如,/ )。尝试将其更改为/r/

$which_text = preg_replace("/r/", "", $which_text);

您对preg_replace使用了错误的语法。使用简单的str_replace函数,您的字符串替换将正常工作:

$which_text = str_replace("r", "", $which_text);

preg_replace旨在用于匹配复杂的模式,例如,任何单词后跟空格

如果要替换已知的确切子字符串,则必须改用str_replace

阅读有关preg_replace语法的更多信息

最新更新