Home » Php » php – Function split() is deprecated , preg_split(): No ending delimiter ',' found

php – Function split() is deprecated , preg_split(): No ending delimiter ',' found

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have a PHP script written 10 years ago. Now we moved the script to new server and it’s not working. The line that has problem is:

$p_industry = split(',', $member['p_industry']);

The testing email receive this error message:

Function split() is deprecated .

I researched this website and then I replaced the script with

$p_industry = preg_split(',', $member['p_industry']);

Then the testing email receive this different error message:

preg_split(): No ending delimiter ‘,’ found

When I change script to

$p_industry = explode(',', $member['p_industry']);

I did not receive any email for error message. But the script seems not working either. It seems not working in a way that it doesn’t even send error message to testing email.

What should I change to the script? Can you give me specific answer?

How to&Answers:

Preg_* functions has to have delimiters around pattern. I use ~.

$p_industry = preg_split('~,~', $member['p_industry']);