Voting

: six plus one?
(Example: nine)

The Note You're Voting On

Daniel Schroeder
14 years ago
If you want to split by a char, but want to ignore that char in case it is escaped, use a lookbehind assertion.

In this example a string will be split by ":" but "\:" will be ignored:

<?php
$string
='a:b:c\:d';
$array=preg_split('#(?<!\\\)\:#',$string);
print_r($array);
?>

Results into:

Array
(
[0] => a
[1] => b
[2] => c\:d
)

<< Back to user notes page

To Top