为cURL内容创建容器

时间:2013-07-22 03:04:41

标签: php css curl

我正在使用curl来获取页面。问题是,我试图让自己的“标题”div成为底部的卷曲内容。来自cURL的CSS虽然搞乱了我的格式。如何在不放入iframe的情况下包含cURL内容?

public function curl ($url, $options)
{
    $handle = curl_init($url);
    curl_setopt_array($handle, $options);
    ob_start();
    $buffer = curl_exec($handle);
    ob_end_clean();
    curl_close($handle);
    return $buffer;
}

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

$content = curl($url, $options = array());

preg_match('/<body>(.*?)</body>/is', $content, $matches);

if(!empty($matches)) {

 $body = $matches[0];

 //header with your css
 echo $header;

 //parsed content 
 echo $body;

 //footer
 echo $footer;
}

注意:代码未经过测试。

希望它有所帮助。

答案 1 :(得分:0)

您可以尝试仅输出其正文以避免加载任何其他css文件。