Disk Space:50MB Data transfer:500MB Domains:1 Email Accounts:2
I need the required output in this format.
Disk Space:50MB
Data transfer:500MB
Domains:1
Email Accounts:2
Disk Space:50MB Data transfer:500MB Domains:1 Email Accounts:2
I need the required output in this format.
Disk Space:50MB
Data transfer:500MB
Domains:1
Email Accounts:2
$str="Disk Space:50MB Data transfer:500MB Domains:1 Email Accounts:2";
$match=null;
preg_match_all('/[^\:]+\:[^\s]+/i',$str,$match);
print_r($match);
outputs:
Array
(
[0] => Array
(
[0] => Disk Space:50MB
[1] => Data transfer:500MB
[2] => Domains:1
[3] => Email Accounts:2
)
)
This assumed that your string will be in [name][colon][value][space] format, where no [colon] in [name], and no [space] in [value].
Also, you may want to trim the matched result.
: to = in the matched array.foreach($match[0] as $val) echo str_replace(":","=",trim($val))."<br />"; This will output Disk Space=50MB<br />Data Transfer=500MB<br /> etc.