There are phone numbers in format (string):
0930001122, 0960001122
0930001122; 0960001122
0930001122.0960001122.
Accordingly, I want to split into an array of symbols: ,. ;
On the comma and point with the comma, it enters the array, but on the symbol of the point – does not want.
Infa pulls up from the database table (row type)
$ kitchen = preg_split ("/, /", $ obj- & gt; phone); // Sing the comma
If (Count ($ Kitchen) == 1) {
$ kitchen = preg_split ("/; /", $ obj- & gt; phone); // If the length of the array is equal to one, it means there or one phone, or the previous split did not work, trying to split on a point with a comma.
}
If (Count ($ Kitchen) == 1) {
$ kitchen = preg_split ("/./", $ Obj- & gt; phone); // If the array length is one, it means there or one phone, or previous splits did not work. We are trying to divide the string on the point.
}
With such code, the first two formats of phones are divided into an array, and the third is simply written as 0, emptiness.
Answer 1, Authority 100%
It is not clear what is your problem. The code is quite worker, but can be reduced to:
$ phone = '0930001122, 0960001122,0930001122; 0960001122; 0930001122.0960001122. ';
$ kitchen = preg_split ("/ (\ s +)? [.;,] (\ s +)? /", $ Phone);
Print_R ($ Kitchen);
We get the result
array
(
[0] = & gt; 0930001122.
[1] = & gt; 0960001122.
[2] = & gt; 0930001122.
[3] = & gt; 0960001122.
[4] = & gt; 0930001122.
[5] = & gt; 0960001122.
[6] = & gt;
)