我想只读取文件中的字母内容而忽略其余的特殊字符。怎么做到这一点?
我打算用
$content = file_get_contents($argv[1]);
如何确保$contents
不包含任何特殊字符。
答案 0 :(得分:2)
如果您只需要提取A-Z和a-z,请使用:
abcdzjsi3424mmdnsn12312312
$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