Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Jan 2017
    Posts
    246
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Question How To Check For Banned Word On Page With Javascript ?

    Folks!

    Why do you reckon this code does not work ? I only see a blank page.
    The code will need to run everytime cURL loads a page so that the JS can check the page for banned words.

    Code:
    <?php
    /*
    ERROR HANDLING
    */
    
    $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);
    if (curl_errno($curl)) {
        echo 'Error:' . curl_error($curl);
    }
    $response = curl_getinfo( $curl );
    if($response['http_code'] == '200' )
    {
    ?>
    <script>
    $(function(){
    		var pageData = "hello <a>example can have tags! swear word is </a><div> one..</div>";
       if(checkSwear(pageData)== false){
       //redirect to google
       }
    });
    
    function checkSwear(sentance) {
    	
    	var swear_words_arr=new Array("blow", "nut", "asshole");
      var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );
      if(regex.test(sentance)) {
        alert("Please refrain from using offensive words"); /* + alert_text */
        return false;
      } else {
      //alert(1)
      	return true;
      }
    }
    </script>
    <?php
    }
    curl_close($curl);
    ?>

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,998
    Thanks
    36
    Thanked 1,072 Times in 1,068 Posts
    PHP is run on a server, JS is run in a browser. Never the two shall meet, except though ajax.

    Also your JS is two functions and I don't see either being called.

    Why not look for the banned words with PHP code. This was just discussed in the PHP section. A search should reveal it to you.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •