phpsane Posted September 7, 2017 Share Posted September 7, 2017 (edited) Folks, Can you figure-out why the following script fails to find the banned words on the page when the banned words are listed in an array ? <?php /* ERROR HANDLING */ //declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // 1). $curl is going to be data type curl resource. $curl = curl_init(); // 2). Set cURL options. curl_setopt($curl, CURLOPT_URL, 'https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); // 3). Run cURL (execute http request). $result = curl_exec($curl); $response = curl_getinfo( $curl ); if( $response['http_code'] == '200' ) { //Set banned words. $banned_words = array("Prick","Dick","Fag"); //Separate each words found on the cURL fetched page. $word = explode(" ", $result); //var_dump($word); for($i = 0; $i <= count($word); $i++){ foreach ($banned_words as $ban) { if (stripos($word[$i],$ban) !== FALSE){ echo "word: $word[$i]<br />"; echo "Match: $ban<br>"; }else{ echo "word: $word[$i]<br />"; echo "No Match: $ban<br>"; } } } } // 4). Close cURL resource. curl_close($curl); Remember the banned words exist on the page. And No. It is not because the banned words are not text but imgs as I checked the source code of the page and the banned words do exist as text. Check it out yourself, if you have any doubts. I hope it is not because this was set to false: curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); Setting it to "true", how-ever, shows a complete blank page. Why ? Must it not be set to "true" since the page is "httpS" anyway! Edited September 7, 2017 by phpsane Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/ Share on other sites More sharing options...
phpsane Posted September 7, 2017 Author Share Posted September 7, 2017 (edited) Look what the above code shows as result even when some of these banned words exist on the page. https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X Check the img. Edited September 7, 2017 by phpsane Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1550939 Share on other sites More sharing options...
phpsane Posted September 9, 2017 Author Share Posted September 9, 2017 Does anyone have any clue why this is happening ? Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551022 Share on other sites More sharing options...
requinix Posted September 9, 2017 Share Posted September 9, 2017 Oh yeah, I know exactly why it isn't working. And if you paid attention in your other threads then you would know why too. Because we've told you about the problems with using explode(). I'll give you a hint: View Source. Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551024 Share on other sites More sharing options...
phpsane Posted September 9, 2017 Author Share Posted September 9, 2017 Oh yeah, I know exactly why it isn't working. And if you paid attention in your other threads then you would know why too. Because we've told you about the problems with using explode(). I'll give you a hint: View Source. I'm recalling from memory without going to my other threads. Don't tell me, it's has something to do with trailing spaces. Ok, let me see if I can solve the problem with the trim function. Thanks for the hint! Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551059 Share on other sites More sharing options...
phpsane Posted September 9, 2017 Author Share Posted September 9, 2017 (edited) Oh yeah, I know exactly why it isn't working. And if you paid attention in your other threads then you would know why too. Because we've told you about the problems with using explode(). I'll give you a hint: View Source. I checked the source again. Seems like the long list of 68 banned words are within the opening & closing img tag. That means they're not text but an img. I was wondering the other night why they seemed funny like an img. Silly me! Should have relied on my instinct! Now I know. So, I guess my code is working then. If it is failing then it is due to the banned words not being on the page as text but an img and we know no script can read a text on an img. I might aswell test the script on another website. Thanks Edited September 9, 2017 by phpsane Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551060 Share on other sites More sharing options...
requinix Posted September 9, 2017 Share Posted September 9, 2017 (edited) Edited September 9, 2017 by requinix Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551061 Share on other sites More sharing options...
phpsane Posted September 9, 2017 Author Share Posted September 9, 2017 (edited) Whaaaat ! You daaare give up on me! Lol! I still did not understand your hint ? Anyway, taking an interest in these motion imgs, like the one you put. They're not video files but img files. Right ? So, how do you display all those img frames, like that, where 40 frames or so are being played without being redirected to 40 pages where each page hosts 1 frame ? Will have to check what file type it is. Animation file type. Btw, I'm not good with file types. Edited September 10, 2017 by phpsane Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551065 Share on other sites More sharing options...
phpsane Posted September 18, 2017 Author Share Posted September 18, 2017 I'm gonna guess again without checking my other threads, Requinix. Let me guess! You want me to use: strtok. Right ? Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551528 Share on other sites More sharing options...
requinix Posted September 19, 2017 Share Posted September 19, 2017 (edited) If all you're going to do is guess at the answer then there's nothing left to do in this thread. And no, not strok. It has absolutely nothing to do with this. [edit] In the interest of closing out this thread, I'll give you a more or less precise answer. explode()ing on a space requires that there be a space on both sides of the words you're looking for. That is not the case for the HTML you used. That's why explode() isn't working. Edited September 19, 2017 by requinix 1 Link to comment https://forums.phpfreaks.com/topic/304905-loop-searching-the-array-for-banned-words-a-failure/#findComment-1551537 Share on other sites More sharing options...
Recommended Posts