【发布时间】:2013-09-27 09:35:34
【问题描述】:
我正在尝试从给定的 url 解析文本内容。代码如下:
<?php
$url = 'http://stackoverflow.com/questions/12097352/how-can-i-parse-dynamic-content-from-a-web-page';
$content = file_get_contents($url);
echo $content; // This parse everything on the page, including image + everything
$text=escapeshellarg(strip_tags($content));
echo "</br>";
echo $text; // This gives source code also, not only the text content over page
?>
我只想获取写在页面上的文本。没有页面源代码。有什么想法吗?我已经用谷歌搜索过了,但上面的方法只存在于任何地方。
【问题讨论】:
-
您使用
escapeshellarg的原因是什么? -
@CORRUPT:我已经用过了。它还提供源代码。不仅是写在页面上的文字。
-
我将整个内容作为参数传递给 c++ 程序。
escapeshellarg引用''的结果,以便它可以作为单个参数遇到
标签: php