8

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?

Tiny
  • 24,933
  • 92
  • 299
  • 571
happybeauty
  • 81
  • 1
  • 4

1 Answers1

18

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

$p_industry = preg_split('~,~', $member['p_industry']);
pavel
  • 24,015
  • 8
  • 38
  • 57
  • 1
    what `~` is doing here? can u please explain? – Dev Jan 16 '20 at 10:08
  • 1
    @Dev: `preg_*` functions have delimiters around pattern. That's the main task in this question. https://www.php.net/manual/en/regexp.reference.delimiters.php. Or see https://regex101.com, the regex input, there is full syntax too... `DELIM--regex--DELIM--FLAGS`, eg. `~regex~i`, or `#regex#m`, etc. – pavel Jan 16 '20 at 13:54