i'm posting here for a problem i'm facing currently, i have an array where i have to filter values that is preceded by "!" and later count it, i tried array_filter but is of no use i would like to know if there is another way to filter values and separate values preceded by "!" i'm posting the array below with the code to save space
here is the code i have done so far:
$dat= Array
(
[0] => Lorem
[1] => ipsum
[2] => dolor
[3] => sit
[4] => amet,
[5] => consectetur
[6] => adipiscing
[7] => elit.
[8] => <a
[9] => class="btn
[10] => btn-default"
[11] => href="hash_sys.php?tag=bart">
[12] => !bart
[13] => </a>
[14] => Quisque
[15] => sapien
[16] => velit,
[17] => aliquet
[18] => eget
[19] => commodo
[20] => nec,
[21] => !qwerty
[22] => auctor
[23] => a
[24] => sapien.
[25] => Nam
[26] => eu
[27] => neque
[28] => vulputate
[29] => diam
[30] => rhoncus
[31] => faucibus.
[32] => Curabitur
[33] => quis
[34] => varius
[35] => libero.
[36] => <a
[37] => class="btn
[38] => btn-default"
[39] => href="hash_sys.php?tag=qwerty">
[40] => !qwerty
[41] => </a>
[42] => Lorem.
)
foreach($dat as $d){
if(strpos($d ,'!') !== FALSE ){
$d_p="";
$i=0;
$tag="";
$d2=count($dat);
while ($i<$d2) {
$d_w=$dat[$i];
$regex="/!+([a-zA-z0-9._-]+)/";
$regex1="/(?:\s|^)![A-Za-z0-9\-\.\_]+(?:\s|$)/";
$d1=preg_match_all($regex, $dat[$i],$output_preg,PREG_PATTERN_ORDER);
function check_regex($data){
if ($data=="/(?:\s|^)![A-Za-z0-9\-\.\_]+(?:\s|$)/")
{
return $data;
}
}
$d_p= array_column($dat,$output_preg[0][0],$regex1);
$d_f= array_filter($d_p,"check_regex" , ARRAY_FILTER_USE_BOTH);
$d_c= array_count_values($d_p);
print_r($d_p);
foreach ($d_c as $d2) {
if ($d2>1 ) {
$tag=1;
}
}
$i++;
}
if($tag==1){
echo 1;
exit();
} else {
echo 0;
}
}