If the <tt>
and <br/>
tags are the only tags in the string, a simple regex like this will do:
$exploded = preg_split('/\<[^>]+\>/',$newstring, PREG_SPLIT_NO_EMPTY);
The expression:
delimiters start and end with <
and >
respectively
In between these chars at least 1 [^>]
is expected (this is any char except for the closing >
PREG_SPLIT_NO_EMPTY
This is a constant, passed to the preg_split
function that avoids array values that are empty strings:
$newString = '<tt>Foo<br/><br/>Bar</tt>';
$exploded = preg_split('/\<[^>]+\>/',$newstring);
//output: array('','Foo','','Bar',''); or something (off the top of my head)
$exploded = preg_split('/\<[^>]+\>/',$newstring, PREG_SPLIT_NO_EMPTY);
//output: array('Foo', 'Bar')
If, however, you're dealing with more than these two tags, or variable input (as in user-supplied), you might be better off parsing the markup. Look into php's DOMDocument
class, see the docs here.
PS: to see the actual output, try echo '<pre>'; var_dump($exploded); echo '</pre>';
.. I'm new to regular expressions, etc. so I'm trying to get a preg_split expression that will do it. – Jordan Fine Dec 27 '12 at 05:42
/ doesn't work ... not sure if it needs to be escaped or something – Jordan Fine Dec 27 '12 at 05:46