Getting Warning: split(): REG_BADRPT when using the split PHP function

G

How Can We Help?

Getting Warning: split(): REG_BADRPT when using the split PHP function

Getting Warning: split(): REG_BADRPT when using the split PHP function when I try to split a string after each question mark (?).

E.g.

$string = "ABC?DEF?BGT";
list($a,$b) = split('?',$string);

Answer:

  • The reason why this is failing is split gives you the power to use regular expressions
  • Use the explode() function instead
  • If you really need to use the split() function try escaping the character eg. ‘/\?/’

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me