解析字符串响应http [关闭]

I'm going to give a basic example of what I need to be able to do, in the hopes that somebody can point me in the right direction

I prepare the URL required for the HTTP GET request to get data (trains between destinations by simply typing the name of the stations) from oncf.ma

I used cURL for that purpose but the response is string. here is the code i used,

 $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL,'www.oncf.ma/Pages/ResultatsHoraire.aspx?depart=BERRECHID&arrivee=BENGUERIR&CodeRD=0093&CodeGD=00183&CodeRA=0093&CodeGA=00120&heure=0000&date=19/11/2013');
$content = curl_exec($ch);
echo $content;

What I need to do, that I don't know how to do, is how can manipulate string to get just data needs and not all html parsing to string.

response is change if we change parameters.

You can use Regular Expressions for that purpose. Here are some nice getting-started guides for regex under php.

You can also use a DOM Parser like phpQuery which imitates the behaviour of jQuery by letting you query the DOM using css selectors

Use XPath to query the DOM and extract the data you want to process. See "php xpath table parsing question" for an example.

It looks like the result is HTML. In that case, you'll want to create a DOMDocument (see http://us1.php.net/book.dom for all of the PHP documentation on that topic) and process it that way.

Your first step will look like this:

$document = new DOMDocument();
$document->loadHtml( $content );

Now, you can manipulate "$document" using its member functions. For example, to get all of the "td" instances, you could call:

$elements = $document->getElementsByTagName( "td" );

(See http://us1.php.net/manual/en/domdocument.getelementsbytagname.php for more information on that function.)