<?php
$str1 = "CN=CMPPDepartemental_Secretariat,OU=1 - Groupes de sécurité,OU=CMPP,OU=Pole,OU=Utilisateurs,DC=ricky,DC=fr";
$str2 = "CN=CMPPDepartemental_Direction,OU=1 - Groupes de sécurité,OU=CMPP,OU=Pole,OU=Utilisateurs,DC=ricky,DC=fr";
var_dump(find_by_keyword($str2, "CN="));
function find_by_keyword( $string, $keyword ) {
$array = explode(",",$string);
$found = [];
// Loop through each item and check for a match.
foreach ( $array as $string ) {
// If found somewhere inside the string, add.
if ( strpos( $string, $keyword ) !== false ) {
$found[] = substr($string, strlen($keyword));
}
}
return $found;
}
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- array(1) {
[0]=>
string(27) "CMPPDepartemental_Direction"
}
preferences:
104.84 ms | 406 KiB | 5 Q