<?php
function escape_possible($chaines, $sepChmp, $dlmtTxt) {
$escape_possible = [];
if( preg_match_all("#((?<![$dlmtTxt])$dlmtTxt(?!$dlmtTxt)).*?(?1)#su", $chaines, $encadres) ) {
foreach( $encadres[0] as $encadre) {
if( preg_match_all("#.(?=$sepChmp)#su", $encadre, $escapes) ) {
foreach($escapes[0] as $escape) {
if(isset($escape_possible[$escape])) $escape_possible[$escape]++;
else $escape_possible[$escape] = 1;
}
}
}
}
arsort($escape_possible);
return $escape_possible;
}
// cas 1
$sepChmp = ';';
$dlmtTxt = '"';
$chaines = '"il a dit ""aie"" ; en criant"
"Laurent TOGIER";"19\; Rue Bréa";75006;PARIS
Laurent TOGIER;"\; Rue Bréa";75006;PARIS
Laurent TOGIER;"19\;";75006;PARIS
Laurent TOGIER;"\;";75006;PARIS
Laurent TOGIER;"19\; Rue\; Bréa";75006;PARIS
Laurent TOGIER;"\;\;";75006;PARIS';
var_dump(escape_possible($chaines, $sepChmp, $dlmtTxt));
/*
array(2) {
["\"]=>
int(8)
[" "]=>
int(1)
}
*/
// cas 2
$sepChmp = '§'; // utf-8
$dlmtTxt = '`';
$chaines = '`Laurent TOGIER`§`19/§ Rue Bréa`§75006§PARIS
Laurent TOGIER§`/§ Rue Bréa`§75006§PARIS
Laurent TOGIER§`19/§`§75006§PARIS
Laurent TOGIER§`/§`§75006§PARIS
Laurent TOGIER§`19/§ Rue/§ Bréa`§75006§PARIS
Laurent TOGIER§`/§/§`§75006§PARIS
`il a dit ``aie`` § en criant`';
var_dump(escape_possible($chaines, $sepChmp, $dlmtTxt));
/*
array(2) {
["/"]=>
int(8)
[" "]=>
int(1)
}
*/
- Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(2) {
["\"]=>
int(8)
[" "]=>
int(1)
}
array(2) {
["/"]=>
int(8)
[" "]=>
int(1)
}
preferences:
157 ms | 403 KiB | 162 Q