我正在使用php,我想以更快的方式从url获取内容。
这是我使用的代码。
代码:(1)使用php以更快的方式获取内容使用php
<?php
$content = file_get_contents('http://www.filehippo.com');
echo $content;
?>
这是很多其他方法来读取文件,如fopen()
,readfile()
等,但我认为file_get_contents()
比这些方法快。
在我上面的代码中,当你执行它时,你会发现它从本网站的所有东西甚至图像和广告。我只想得到计划HTML文本没有CSS样式,图像和广告。我怎样才能得到这个。
看到这个了解。
CODE:(2)
<?php
$content = file_get_contents('http://www.filehippo.com');
// do something to remove css-style, images and ads.
// return the plain html text in $mod_content.
echo $mod_content;
?>
如果我是这样做上述然后我会在错误的方式,因为我已经得到变量$content
的全部内容,然后修改它。
这里可以是任何函数方法或其他任何从url直接获取纯文本html文本的方法。
下面的代码只是为了理解而写的,这不是原来的php代码。
IDEAL CODE:(3);
<?php
$plain_content = get_plain_html('http://www.filehippo.com');
echo $plain_content; // no css-style, images and ads.
?>
如果我能得到这个功能,它会比别人快得多。这可能吗?
谢谢。
页面'HTTP:// www.filehippo.com'嵌入了已经脚本和样式。你不能选择不下载它,但你可以过滤它。 –