- var_dump: documentation ( source)
- stripslashes: documentation ( source)
- preg_match_all: documentation ( source)
- str_replace: documentation ( source)
- array_filter: documentation ( source)
- sprintf: documentation ( source)
<?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);