我需要一个代码,在字符串中找到一个单词,如果使用php字符串和数组找到它,则显示一条消息! [英] I need a code that finds a word in a string and displays a message if its found using php strings and arrays!
本文介绍了我需要一个代码,在字符串中找到一个单词,如果使用php字符串和数组找到它,则显示一条消息!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要它,以便如果我有一个像轮胎,黑客,它这样的词,在数组中它会找到这个字符串中的单词:re'tire'ment is pol'it' ly w'hack'y!
我有这个代码只有当这个单词不是另一个单词的一部分时才有效但我想知道是否有办法找到单词如果它是另一个单词的一部分:
$ bad = array( a, 狗跨度>);
$ string = $ _POST [' 用户名'跨度>];
if (0< count(array_intersect(array_map(' strtolower',explode(' ',$ string)),$ bad)))
{
$ errors [] = ' 用户名不得包含任何不合适的语言。';
}
解决方案
错误 =数组( a, dog );
string =
_POST [' 用户名'];
if (0< count(array_intersect(array_map(' strtolower',explode(' 跨度>,
I need it so that if I have a words like: "tire","hack","it," in an array it would find the words in this string: "re'tire'ment is pol'it'ly w'hack'y!"
I have this code which only works when the word is not part of another word but I was wondering if there was a way to find the word if it part of another word:
$bad = array("a","dog");
$string = $_POST['Username'];
if (0 < count(array_intersect(array_map('strtolower', explode(' ', $string)), $bad)))
{
$errors[] = 'The user name must not contain any inapproprate language.';
}
解决方案
bad = array("a","dog");
string =
_POST['Username']; if (0 < count(array_intersect(array_map('strtolower', explode(' ',
这篇关于我需要一个代码,在字符串中找到一个单词,如果使用php字符串和数组找到它,则显示一条消息!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文