3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sepChmp = '`'; $dlmtTxt = '§'; $sepLigne = "\v"; $chaines = '§Laurent TOGIER§`§19\` Rue Bréa§`75006`PARIS'. $sepLigne . 'Laurent TOGIER`§\` Rue Bréa§`75006`PARIS'. $sepLigne . 'Laurent TOGIER`§19\`§`75006`PARIS'. $sepLigne . 'Laurent TOGIER`§\`§`75006`PARIS'. $sepLigne . 'Laurent TOGIER`§19\` Rue\` Bréa§`75006`PARIS '. $sepLigne . 'Laurent TOGIER`§\`\`§`75006`PARIS'. $sepLigne . '§il a dit §§aie§§ ` en \\criant§'; $lignes = []; $regexp = sprintf( '#(?<![%1$s\\\])%1$s(?!%1$s)(?<data>.*?)(?<![%1$s\\\])%1$s(?<sep>[%2$s%3$s]|$)|(?<data>[^%2$s%3$s]*)(?<sep>[%2$s%3$s]|$)#Jus', $dlmtTxt, $sepChmp, $sepLigne ); if( preg_match_all($regexp, $chaines, $matches, PREG_SET_ORDER) ) { $ligne = []; foreach($matches as $match) { $ligne[] = stripslashes(str_replace(["\\$dlmtTxt", "$dlmtTxt$dlmtTxt"], $dlmtTxt, $match['data'])); if($match['sep'] !== $sepChmp && count(array_filter($ligne))) { $lignes[] = $ligne; $ligne = []; } } } var_dump($lignes);

preferences:
26.2 ms | 402 KiB | 5 Q