I have a record with a value of
Name::Address::Job Description
how do I remove the :: and put all the data into an array like
array("Name","Address","Job Description")
Thank a lot.
I have a record with a value of
Name::Address::Job Description
how do I remove the :: and put all the data into an array like
array("Name","Address","Job Description")
Thank a lot.
You can use explode
, like this:
$str = 'Name::Address::Job Description';
$delimiter = '::';
$array = explode($delimiter, $str);
To perform the replacement, you can use str_replace
:
$str = str_replace($delimiter, '', $str);
Alternatively, you can simply implode
on the return value of explode
:
$str = implode($array);
For more advanced splitting you can use
$str = 'Name::Address::Job Description';
$delimiter = '::';
$array = preg_split("/$delimiter/",$str);
Array
(
[0] => Name
[1] => Address
[2] => Job Description
)
preg_split is a Regex split while explode is a string split.
Regex would be useful if you had variation in your data: IE
$str = 'Name::Address:Job Description;Job Title';
$delimiter = '::?|;';
$array = preg_split("/$delimiter/",$str);
Array
(
[0] => Name
[1] => Address
[2] => Job Description
[3] => Job Title
)