I have a sentence like this :
i am a superhero. @xxxxx August 28, 2016 at 09:29AM
What i want is like this :
i = 1
am = 1
a = 1
superhero = 1
@xxxxx = 1
August 28, 2016 at 09:29AM = 1
i have succeed to count all of them with this :
$string = "i am a superhero, @xxxxx August 28, 2016 at 09:29AM";
$result= array_count_values(explode(' ', $string));
But what i want is to count August 28, 2016 at 09:29AM
as 1 word. Does it possible ?
Probably a better pattern, but this could work as an example.
$string = "i am a superhero, @xxxxx August 28, 2016 at 09:29AM";
$string = preg_replace('/(\w+) (\d+), (\d+) at (\w+)/i', '$1_$2_$3_$4', $string);
$result= array_count_values(explode(' ', $string));
var_dump($result);
If your date format is always the same then you can subract 4 from the total count.
$string = "i am a superhero, @xxxxx August 28, 2016 at 09:29AM";
$result= count(explode(' ',$string))-4;
echo $result;
Output:
6