use preg_split instead of split

2019-02-28 16:09发布

问题:

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