Search This Blog

Sunday, October 11, 2009

PHP: Warning: split() [function.split]: REG_EMPTY in xxx

I try to php split to split out the concatenated data. Below are the sample that i use

$comp = "V1001|VI003";

$comp_arr = split("|",$comp);

i hit error:

PHP: Warning: split() [function.split]: REG_EMPTY in xxx

after search around and found that the issue is caused by symbol "|".
"|" is an operator in PHP. If want to use the this symbol as a delimiter, we must excape it with a back slash, "\|"

now it become

$comp = "V1001|VI003";

$comp_arr = split("\|",$comp);

and it works.

Hope this help


MuseiKaze said...

Oh man that helped alot, I couldn't figure out why I was getting that error for ereg_replace. Thanks!

Leon said...

Thanks, I was wondering about this error. I used || so I had to escape it like so, \|\|

asad_ddos said...

Great post thank you so much...