php - Split a string by forward slash but ignore the <\ in the string -


i have string similar

word1/word2/word3/<b>word3</b> 

i want explode string forward slash. can following result.

array = ( [0] => 'word1', [1] => 'word2', [2] => 'word3', [3] => '<b>word3</b>' ); 

but i'm unable above result. instead i'm getting following result

array = (     [0] => 'word1',     [1] => 'word2',     [2] => 'word3',     [3] => '<b>word3<',     [4] => 'b>'     ); 

what regular expression should use use preg_split function achieve expected results?

with preg_split function , specific regex pattern:

$s = 'word1/word2/word3/<b>word3</b>'; $result = preg_split('~(?<!<)/~', $s); print_r($result); 
  • ~ - treated regex expression separator

  • (?<!<)/ - negative lookbehind assertion, assures forward slash / not preceded <

the output:

array (     [0] => word1     [1] => word2     [2] => word3     [3] => <b>word3</b> ) 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -