0

I already have the following in place to explode the br's in $tmp..

  $tmp = explode('<br>', $tmp);
  echo $tmp[0];
  echo "<br>";
  echo $tmp[1];

Now, in $tmp[0] there is a bunch of text, separated by a pipeline "|". ie: word1|word2|word3|word4|word5 take notice, the last once doesn't end in a pipeline..

How can I explode $tmp[0] to grab each bit of text, turn them into an array, ie: $pipetxt[0], $pipetxt[1], etc. without the pipelines..

Can I do the exact same as the above, after the above occurs.. but go;

$pipetxt = explode('|', $tmp[0]);
echo $pipetxt[0];
echo "<br>";
echo $pipetxt[1];

Thank you!

4
  • So... what's wrong with what you already have again? Commented Dec 17, 2010 at 19:20
  • I haven't tested the second explode.. was just checking if that was the correct way and if I was able to do it on an already exploded array? Commented Dec 17, 2010 at 19:23
  • Functions never care about what something used to be, only what it is. Commented Dec 17, 2010 at 19:24
  • There is no such thing as an "already exploded array". Arrays and strings don't have a concept of being exploded. $tmp starts as being a string (some text) and when you explode it you get an array of strings (a "bag" of strings). So your $tmp variable now points at a bunch of strings. When you then explode $tmp[0] what you are doing is taking the "0th" (first) element of the array (another string) and exploding it to obtain a new array of strings. You can continue in this way indefinitely (the worst that can happen is getting an array with a single string in it). Commented Dec 17, 2010 at 20:01

2 Answers 2

1

Your explode looks good, and you can output all your $pipetxt with foreach():

foreach($pipetxt as $out)
  echo $out . "<br>";
Sign up to request clarification or add additional context in comments.

Comments

0

Yes

But you should probably adopt some loops.

$tmp = explode('<br>', $tmp);

foreach($tmp as $pipeline){
 $pipetxt_array = explode('|', $pipeline);
 foreach ($pipetxt_array as $output){
  echo $output."<br />";
 }
}

1 Comment

Thanks Ben - would have chosen this as the answer, although styu was in first with a working method. I'll test yours out shortly, looks great though! Thanks for the advice!

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.