Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Why strpos Fails To Find Banned Words On Page ?

php banned words strpos

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 18 September 2017 - 02:31 PM

Php programmers,

 

Can you see why the script is unable to find the banned words that exist on the page ? It is a puzzling incident!

<?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);
 
 
$curl = curl_init();
 
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 );
 
$result = curl_exec($curl);
$response = curl_getinfo( $curl );
 
if( $response['http_code'] == '200' )
{
    
    $banned_words = array("Prick","**","**");
 
    //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>";  
            }
        }
    }
}
 
curl_close($curl);

Edited by uniqueideaman, 18 September 2017 - 04:04 PM.