Skip to content
Advertisement

How to count all the words with special characters

I have a question about a String i want to count all the characters in the string. Like if i have a string

"Hello world & good morning. The date is 18.05.2016"

Advertisement

Answer

You can try this code.

<?php
 $file = "C:UserssinghDesktopTalkative Challengebase_example.txt"; 
 $document = file_get_contents($file); 
 $return_array = preg_split("/[s,]+/",$document);
 echo count($return_array);
 echo $document;
?>

Hopefully it will be working fine.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement