use preg_split instead of split

2019-02-28 16:14发布

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?

2条回答
聊天终结者
2楼-- · 2019-02-28 17:04

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)
                      ^           ^
查看更多
神经病院院长
3楼-- · 2019-02-28 17:07

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

 $lines = preg_split ("/\r\n|[\r\n]/", $data);
                       ^           ^
查看更多
登录 后发表回答