Unbreakable Unbreakable - 1 year ago 63
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download