use preg_split instead of split

北战南征 提交于 2019-12-02 09:42:32

问题


I'm using FPDF v. 1.53. Now I switched to a newer PHP version. The function split is now deprecated. I had on line 108 the following code in fpdf_eps.php:

$lines = split ("\r\n|[\r\n]", $data);

I wanted to change it to preg_split

$lines = preg_split ("\r\n|[\r\n]", $data);

but than the script seems to have an error and I only get the message page not found (I always get this if a script has an error). What is wrong? The regexp?


回答1:


When using regular expressions with preg, you should contain your regex inside slashes. Your regex should look like this:

$lines = preg_split ("/\r\n|[\r\n]/", $data)
                      ^           ^



回答2:


You've missed the trailing / aswell as the one in front of the pattern:

 $lines = preg_split ("/\r\n|[\r\n]/", $data);
                       ^           ^


来源:https://stackoverflow.com/questions/8255422/use-preg-split-instead-of-split

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!