0

i got a

$str ="sometxt<br>another<br>moretext<br>evenmoretext<br>";

i'm trying to output the string in one array per line.

kinda like this..

[0] => Array
        (['stuff'] => sometext
        )
[1] => Array
        (['stuff'] => another
        )
[2] => Array
        (['stuff'] => moretext
        )
[3] => Array
        (['stuff'] => evenmoretext
        )

i'm using regex to get the str.. if u need more clarification..i will do. thanks in advance

2
  • sorry i don't get what you want to do? do you want to split the string into an array? Commented Sep 13, 2010 at 2:42
  • doesnt really make any sense. why are you putting "stuff" in there? Commented Sep 13, 2010 at 2:53

2 Answers 2

3

Try this:

$arr = explode("<br>", $str);

$resp = array();
foreach ( $arr as $val ){
  $resp[] = array("stuff" => $val);
}

I think this code would solve your dilemma. Tell me if you need any clarification.

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

Comments

1

Try this:

<?php
    $str ="sometxt<br>another<br>moretext<br>evenmoretext<br>";
    $r = array("stuff" => explode("<br>", $str));
    print_r($r);
?>

Array
(
    [stuff] => Array
        (
            [0] => sometxt
            [1] => another
            [2] => moretext
            [3] => evenmoretext
            [4] => 
        )

)

2 Comments

I think that the endgame is not just the output, and beside that, you'd need to add a <pre> tag before and after the print_r to get the response you placed ;) Nice one anyways!
I use this: Header('Content-Type:text/Plain')

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.