Extract URL contents using PHP, JQuery and AJAX

Do you want to extract url contents and display it to the user before he posts it to your site?…..

Just check it out the below code….

1. Starting with Basic HTML

<html>

<head>

</head>

<body>

<textarea id=”urls” cols=”40″ rows=”8″ placeholder=”Enter a url here…”></textarea>

<div id=”extr”></div>

</body>

</html>

2. The Javascript Code

Insert this code between the head tag of your html file….

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js></script>

<script>

$(function(){

$(‘#urls’).live(“keyup”,function(){

$.ajax({

type: “POST”,

url: “extract.php”,

data: “url=” + $(‘#urls’).val(),

cache: false,

success:function(html)

{

$(‘#extr’).html(html);

}

});

});

});

</script>

3.The extract.php file

<?php

                         if(isset($_POST[‘url’]))

{

$url = $_POST[‘url’];

                                  if($url == ”)

{

                                           echoURL Mustnot be Empty…Please Enter something…“;

}

                                  else{

                                       echo file_get_contents($ur;);

}

}

              ?>

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s