Jump to content

Loop Searching The Array For Banned Words A Failure


phpsane

Recommended Posts

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!

Link to comment
Share on other sites

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
Share on other sites

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
Link to comment
Share on other sites

:facewall:

 

jJmiG2h.gif

 

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.