Following is the String that holds the contact info. This string is dynamic i.e. sometimes new fields eg: mobile number may add up or old fields say: tel number may delete.
<?php $str =
"tel: (123) 123-4567
fax : (234) 127-1234
email : [email protected]";
$newStr = explode(':', $str);
echo '<pre>'; print_r($newStr);
?>
Output of the code is:
Array
(
[0] => tel
[1] => (123) 123-4567
fax
[2] => (234) 127-1234
email
[3] => [email protected]
)
But the output needed is in the following format:
Array
(
[tel] => (123) 123-4567
[fax] => (234) 127-1234
[email] => [email protected]
)
I tried exploding it in may ways... but didn't work. please guide.
:
. So between(123) 123-4567
andfax
there is no separator like:
. So you are getting both of them in the same value. – Pankit Kapadia Dec 11 '12 at 6:47(123) 123-4567
andfax
– Pankit Kapadia Dec 11 '12 at 6:51