我正在尝试使用 cURL 从另一个 URL 获取/获取文本。我从中获取文本的位置是在具有动态(非静态)数据的空白 HTML 文档中,因此没有要过滤的 HTML 标记。这是我到目前为止所得到的:
$c = curl_init('http://url.com/dataid='.$_POST['username']);
curl_setopt(CURLOPT_RETURNTRANSFER, true);
curl_setopt(CURLOPT_FRESH_CONNECT, true);
$html = curl_exec($c);
if (curl_error($c))
die(curl_error($c));
// Get the status code
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
这完美地工作,但是在动态 HTML 文档的末尾有不需要的文本,“ #endofscript ”(不带引号)。这会被抓取/获取,那么怎么做才能不抓住它呢?我试过查看“ strpos ”等,但我不确定如何将它与 cURL 集成。
所有/任何帮助将/将不胜感激。:)
编辑:我目前使用的代码:
<?php
$homepage = file_get_contents('http://stackoverflow.com/');
$result = substr("$homepage", 0, -12);
echo $result;
?>