I want to numeric values and special charectors values in str_word_count() so how can do that.
example:
$str = str_word_count("B2B my78:test@ Number&10",1);
print_r($str);
Output
Array (
[0] => B [1] => B [2] => my [3] => test [4] => Number
)
but I want to Out put Like this
Array (
[0] => B2B [1] => my78:test@ [2] => Number&10
)
preg_match_all behaves almost like st_word_count, in that it can return the number of matches and an array of words in your string. By using it, you can have the utmost flexibility in defining what exactly constitutes a "word."
$count = preg_match_all('/[a-zA-Z0-9@&:]+/', $str, $matches);
preg_split('/\s+/', $str)
perhaps?
The php.net documentation page shows a very nice example of doing that, so I modified it to fit your example:
$str = "B2B my-78:test@ Number&10";
$array = str_word_count($str, 1, '1234567890:@&');
But you can use regular expressions or explode
if you need more customized results.
Try this:
<?php
$str = "B2B my-78:test@ Number&10";
$array = explode(' ', $str);
echo '<pre>';
print_r($array);
?>
- Thanks