lolagi lolagi - 5 months ago 22
PHP Question

How to count value from strstr function php?

I try to get value after symbol '@' and count it. But this code doesn't give the correct result. How to fix it?

$t="Hi, I invite @nina and @nana to come to my party tomorow";
$arr=explode(' ', $t);
foreach($arr as $user ) {
$result=strstr($user, '@');
$total = $count($result);
}
echo $total;



Result = 1

Expected Result =2

Answer

Why don't you explode it with @?

$t="Hi, I invite @nina and @nana to come to my party tomorow";
$arr=explode('@', $t);
$total = count($arr)-1;
echo $total;