0
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
6
  • what do you have and what exactly do you want? Commented Nov 21, 2012 at 7:15
  • what is the separator of one string Commented Nov 21, 2012 at 7:16
  • You can try preg_split or just regular preg_match function to do that. Commented Nov 21, 2012 at 7:17
  • from database i am getting the value for description like the above output in string format, now i want to break it as shown above Commented Nov 21, 2012 at 7:18
  • It cannot ne done, if you do not have a delimiter other than SPACE for your values, unless you can guarantee that there is no space character inside your values. Commented Nov 21, 2012 at 7:18

2 Answers 2

5
$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.

Sign up to request clarification or add additional context in comments.

6 Comments

[RESPONSE] code = 200 description = Command completed successfully property[domaincheck][0] = 211 Domain name not available property[domainchecktime][0] = 0.238 property[domaincheck][1] = 211 Domain name not available property[domainchecktime][1] = 0.238 queuetime = 0 runtime = 0.251 EOF
just we need to display as the above format, can you please help me how to split
@GangaRaju You can just replace the : to = in the matched array.
@GangaRaju Like this: foreach($match[0] as $val) echo str_replace(":","=",trim($val))."<br />"; This will output Disk Space=50MB<br />Data Transfer=500MB<br /> etc.
i need to workout for the below example: [RESPONSE] code = 200 description = Command completed successfully property[domaincheck][0] = 211 Domain name not available property[domainchecktime][0] = 0.238 property[domaincheck][1] = 211 Domain name not available property[domainchecktime][1] = 0.238 queuetime = 0 runtime = 0.251 EOF can you please consider this.
|
-1
<?php
echo nl2br("text\r\n");
?>

1 Comment

OP wants it returned as an array not have it broken into different lines with HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.