-3

I used this code to fetch all the content of the website page.

$url = file_get_contents('https://berojgarjobs.com/forms/AirForceAFCAT.php');  echo $url;

This code shows all the content of the website but i want only those content which is within <table></table> tag. you can use javascript ,php,curl any to fetch the particular content within the tag from any website

suggest the answer if you can?

2 Answers2

0

You can use PHP DOMDocument's loadHTML:

$doc = new DOMDocument();
$doc->loadHTML($url);

Then obtain the TABLE node from that object.

user2342558
  • 5,567
  • 5
  • 33
  • 54
0

You may use preg_match_all function:

$url = file_get_contents('https://berojgarjobs.com/forms/AirForceAFCAT.php');
$pattern = "/<table(.*)<\/table>/i";
preg_match_all($pattern, $url, $match);
$table = $match[0][0];
echo $table;

There is other way:

$url = file_get_contents('https://www.sarkariexam.com/canara-bank-recruitment-2012/994');
$tables = [];
$pos = 0;
do {
    $start = strpos($url, '<table', $pos);
    $end = strpos($url, '</table', $pos);
    if ($end !== false && $start !== false) {
        $tables[] = substr($url, $start, $end - $start + 8);
        $pos = $end;
    }
} while ($end !== false && $start !== false);
Vladimir
  • 1,373
  • 8
  • 12
  • this is not work for $url = file_get_contents('https://www.sarkariexam.com/canara-bank-recruitment-2012/994'); $pattern = "/