0

I'm trying to turn this string:

> President Obama pointed blabla<br /> <br /> The only way I get this
> stuff <br /> <br /> I'm consulting with the Pentagon, with <br /> <br
> />

into this array: (new array element for each "<br /> <br />")

array (
[0] => President Obama pointed blabla
[1] => The only way I get this stuff 
[2] => I'm consulting with the Pentagon, with 
);

I tried to use explode("<br /><br /> ", $string) but it doesn't work. Any ideas?

1
  • 1
    explode("<br /> <br /> ", $string) Note the space between the 2 <br />s. Commented Mar 28, 2012 at 14:58

4 Answers 4

1

Looks like you just need to remove the first two characters of each line ("> "), concatenate all the lines, then do your explode (noting the missing space, as others have pointed out).

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

Comments

1

In your case explode("<br /> <br />", $string); would work.

More generally, you can add: $string = str_replace('<br /> <br />', '<br /><br />', $string); before the previous line if you have some lines that are separated by <br /> <br /> and some by <br /><br />

Comments

0

Try adding a space between your <br /> tags in the explode function.

Comments

0

Unless it was a typo, you are missing a space in your explode() between each
. Alternatively you could do:

$br2arr = array_filter(preg_split("/([\s\b]*<br \/>[\s\b]*)|([\s\b]*<br>[\s\b]*)/", $str));

Which should do what you want in any case/format

Comments

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.