如何从PHP文件中只读取A-Z和a-z

时间:2016-07-03 06:46:14

标签: php

我想只读取文件中的字母内容而忽略其余的特殊字符。怎么做到这一点?

我打算用 $content = file_get_contents($argv[1]);

如何确保$contents不包含任何特殊字符。

2 个答案:

答案 0 :(得分:2)

如果您只需要提取A-Z和a-z,请使用:

的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

希望这有效。

答案 1 :(得分:0)

def whichkeyword(title) action = title[/(download|buy)/i] public_send action.downcase.to_sym, title if action end