I use codeigniter.I want search in site contents for several word, that did existence it word in it site or no? if existence a word (of all words) in it site return is FALSE. i tried as following code but get error. How can done it?
DEMO: http://codepad.viper-7.com/rFiL01
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'stackoverflow.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
$link[] = array("Questions", "Favorite", "myfoodho");
foreach($link as $val){
stristr($contents,$val); // Line 148
//if(){
// return true;
//}else{
// return false;
//}
}
?>
Error:
A PHP Error was encountered
Severity: Warning
Message: stristr() [function.stristr]: needle is not a string or an
integerFilename: views/exchange.php
Line Number: 148
When you write
you are creating an array that contains another array, that is:
In the foreach loop you’re just going through the outer array and therefore
$valcontains the inner array, not the string values.The solution is to remove the brackets and just assign the array to the variable.
Debugging tip: The error message says “needle is not a string or an integer”. The “needle” of that function is the second parameter (check the docs if you’re not sure). You can then add
var_dump( $val )right before that line to check what the value actually is, if it’s not a string or an integer.