I want to read only the alphabetic content from a file and neglect the rest of the special characters. How to achieve this?
I intend to use $content = file_get_contents($argv[1]);
How can I make sure $contents
does not contain any special character.
If you need to extract only AZ and az, use this:
abcdzjsi3424mmdnsn12312312
$content = file_get_contents('test.txt');
$only_az = preg_replace('/[^a-zA-Z\s]/', '', $content);
echo $only_az; //Output: abcdzjsimmdnsn
Hope this works.
$content = preg_match_all('/[a-zA-Z]/', $content );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.