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
Post a Comment