简体   繁体   中英

How to read only A-Z and a-z from a PHP file

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:

test.txt

abcdzjsi3424mmdnsn12312312

test.php

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM