factoring2117 Posted January 10, 2009 Share Posted January 10, 2009 Hello everyone, I am fairly new to php and I seem to have run into a problem while writing a script. The script is designed to pull data from profiles on myspace. The part of the script that I am writing now checks for certain keywords on the page. If the certain keywords exist, the user should not be able to add their profile to the page. The problem I am running into is that I am using the while function and I believe I should be using something else. The reason for this is because there are 10 keywords I am checking for, so the script runs 10 times because I am using while. Here is my code: <?php include('config.php'); $target_url = "http://www.example.com/1"; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $html = curl_exec($ch); $select = mysql_query("SELECT * FROM newBan"); while($row = mysql_fetch_array($select)) { if(preg_match("/".$key."/i", $html)) { echo "<p>Sorry you cannot add this profile.</p>"; } else { echo "The rest of the script continues."; } } ?> Is there a better method other than using while? Thanks. Link to comment https://forums.phpfreaks.com/topic/140317-i-need-help-with-my-script/ Share on other sites More sharing options...
Rushyo Posted January 10, 2009 Share Posted January 10, 2009 Add all the keys into one string like so: $allkeys = "(key1|key2|key3|key4)"; and perform one preg_match against that. Link to comment https://forums.phpfreaks.com/topic/140317-i-need-help-with-my-script/#findComment-734310 Share on other sites More sharing options...
factoring2117 Posted January 11, 2009 Author Share Posted January 11, 2009 I don't understand what you mean by adding all the keys into one strong. So I should still use the while function? This is what I tried below, but the array only shows the last keyword in the list. Please help. <?php include('config.php'); $target_url = "http://www.example.com/1"; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $html = curl_exec($ch); $select = mysql_query("SELECT * FROM newBan"); while($row = mysql_fetch_assoc($select)) { $key = array($row['keyword']); $key1 = $key[0]; $key2 = $key[1]; } echo "$key1<br /> $key2"; if(preg_match("/".$key."/i", $html)) { echo "<p>Sorry you cannot add this profile.</p>"; } else { echo "The rest of the script continues."; } ?> Link to comment https://forums.phpfreaks.com/topic/140317-i-need-help-with-my-script/#findComment-734440 Share on other sites More sharing options...
aseaofflames Posted January 11, 2009 Share Posted January 11, 2009 do you want all the keys in key1 and key2? if so use $key1[] in place of $key1 and $key2[] insead of $key2. This will make the keys arrays of the values from the database. Link to comment https://forums.phpfreaks.com/topic/140317-i-need-help-with-my-script/#findComment-734543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.