you don't use curl to display parts of the page
, you use it to fetch the page. then, once you got the page, you must use something else to parse out the part of the page that you're interested in. the page is written in HTML, check this answer for a list of HTML parsing utilities for PHP.
as for how to parse out the specific info from this specific page, there's only 1 tbody
tag in the page, and each player has their own dedicated tr
tag, that is a direct child of that tbody
tag, so you can iterate the tr
children of the tbody
tag to iterate through the players. each of these tr
tags has td
children containing the info you want. the text content of the 2nd td
tag has their name, the 3rd has the age, the 4th has the rating, and the 5th has the potential.
an example using the DOMDocument parser:
<?php
declare(strict_types = 1);
$ch = curl_init ( "https://sofifa.com/players?aeh=22&ptl=84&pth=99&pn=27&pn=25&pn=23" );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
$output = curl_exec ( $ch );
curl_close ( $ch );
$domd = @DOMDocument::loadHTML ( $output );
foreach ( $domd->getElementsByTagName ( "tbody" )->item ( 0 )->getElementsByTagName ( "tr" ) as $tr ) {
$tds = $tr->getElementsByTagName ( "td" );
$player = array (
'name' => trim ( $tds->item ( 1 )->textContent ),
'age' => trim ( $tds->item ( 2 )->textContent ),
'rating' => trim ( $tds->item ( 3 )->textContent ),
'potential' => trim ( $tds->item ( 4 )->textContent )
);
print_r ( $player );
}