Unbreakable Unbreakable - 6 months ago 16
PHP Question

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
does not contain any special character.


If you need to extract only A-Z and a-z, use this:




$content = file_get_contents('test.txt');
$only_az = preg_replace('/[^a-zA-Z\s]/', '', $content);
echo $only_az; //Output: abcdzjsimmdnsn

Hope this works.