我有一个简单的php文件,其中包含一个表单中的GET,用于从目录中提取一些文件。相当简单的代码,但我只需要从字符串中删除非小写字母的字符。我该怎么做呢? (我是新手)。
这里'tis:
<?php $text = $_GET['text_string']; ?>
<form method="GET" action="index.php">Please enter some letters: <input type="text" name="text_string" value=""/> and hit <input type="submit" value="enter" />
</form>
<?php /* Split characters into an array */ $array = str_split($text); ?>
<?php foreach($array as $char) : ?>
<img src="glyphs/<?php print ($char); ?>.jpg"/>
<?php endforeach ; ?>
谢谢!
答案 0 :(得分:3)
要小写(请注意,您也可以使用mb_strtolower来更好地处理字符集,但在这种情况下,您只需保留ASCII字符,因此strtolower就足够了):
$text = strtolower($text);
使用preg_replace删除所有非alpha字符:
$text = preg_replace('/[^a-z]/', '', $text);