PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a problem with this code. The problem is that it only redirect when I ONLY write "word" in the text field. I want it to redirect whenever "word" is submitted even if there is other characters in the textfield.
Is there any code that tells it that it will trigger whenever it finds that array in the text field?
I don't understand your problem. If the var $search contains word then these will both echo YES, just as they do with the strings below (I removed your two references as they are not needed):
function wordsExist($string, $words) {
foreach($words as $word) {
if(stripos($string, $word) !== false) {
return true;
}
}
return false;
}
if (wordsExist('word', array('word'))) {
echo "YES";
}
if (wordsExist('a word and more', array('word'))) {
echo "YES";
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Thats what so strange about this .. Because it used to work fine untill I added a code to pull some information from a database and use it in a similar way:
You're going to have to start showing all of your code, and STOP using the reference op &. You don't need it and it may be confusing you. This works, just as the example I posted earlier. What is the issue:
function wordIsthere($string, $word) {
if(stripos($string, $word) !== false) {
return true;
}
return false;
}
if (wordExist('a word and something', 'word')) {
echo "WORD IS THERE!";
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.