本文整理匯總了PHP中collection::url方法的典型用法代碼示例。如果您正苦於以下問題:PHP collection::url方法的具體用法?PHP collection::url怎麽用?PHP collection::url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類collection
的用法示例。
在下文中一共展示了collection::url方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_content
/**
* 采集內容
* @param string $url 采集地址
* @param array $config 配置參數
* @param integer $page 分頁采集模式
*/
public static function get_content($url, $config, $page = 0)
{
set_time_limit(300);
static $oldurl = array();
$page = intval($page) ? intval($page) : 0;
if ($html = self::get_html($url, $config)) {
if (empty($page)) {
//獲取標題
if ($config['title_rule']) {
$title_rule = self::replace_sg($config['title_rule']);
$data['title'] = self::replace_item(self::cut_html($html, $title_rule[0], $title_rule[1]), $config['title_html_rule']);
}
//獲取作者
if ($config['author_rule']) {
$author_rule = self::replace_sg($config['author_rule']);
$data['author'] = self::replace_item(self::cut_html($html, $author_rule[0], $author_rule[1]), $config['author_html_rule']);
}
//獲取來源
if ($config['comeform_rule']) {
$comeform_rule = self::replace_sg($config['comeform_rule']);
$data['comeform'] = self::replace_item(self::cut_html($html, $comeform_rule[0], $comeform_rule[1]), $config['comeform_html_rule']);
}
//獲取時間
if ($config['time_rule']) {
$time_rule = self::replace_sg($config['time_rule']);
$data['time'] = strtotime(self::replace_item(self::cut_html($html, $time_rule[0], $time_rule[1]), $config['time_html_rule']));
}
if (empty($data['time'])) {
$data['time'] = SYS_TIME;
}
//對自定義數據進行采集
if ($config['customize_config'] = string2array($config['customize_config'])) {
foreach ($config['customize_config'] as $k => $v) {
if (empty($v['rule'])) {
continue;
}
$rule = self::replace_sg($v['rule']);
$data[$v['en_name']] = self::replace_item(self::cut_html($html, $rule[0], $rule[1]), $v['html_rule']);
}
}
}
//獲取內容
if ($config['content_rule']) {
$content_rule = self::replace_sg($config['content_rule']);
$data['content'] = self::replace_item(self::cut_html($html, $content_rule[0], $content_rule[1]), $config['content_html_rule']);
}
//處理分頁
if (in_array($page, array(0, 2)) && !empty($config['content_page_start']) && !empty($config['content_page_end'])) {
$oldurl[] = $url;
$tmp[] = $data['content'];
$page_html = self::cut_html($html, $config['content_page_start'], $config['content_page_end']);
//上下頁模式
if ($config['content_page_rule'] == 2 && in_array($page, array(0, 2)) && $page_html) {
preg_match_all('/<a[^>]*href=[\'"]?([^>\'" ]*)[\'"]?[^>]*>([^<\\/]*)<\\/a>/i', $page_html, $out);
if (!empty($out[1]) && !empty($out[2])) {
foreach ($out[2] as $k => $v) {
if (strpos($v, $config['content_nextpage']) === false) {
continue;
}
if ($out[1][$k] == '#') {
continue;
}
$out[1][$k] = self::url_check($out[1][$k], $url, $config);
if (in_array($out[1][$k], $oldurl)) {
continue;
}
$oldurl[] = $out[1][$k];
$results = self::get_content($out[1][$k], $config, 2);
if (!in_array($results['content'], $tmp)) {
$tmp[] = $results['content'];
}
}
}
}
//全部羅列模式
if ($config['content_page_rule'] == 1 && $page == 0 && $page_html) {
preg_match_all('/<a[^>]*href=[\'"]?([^>\'" ]*)[\'"]?/i', $page_html, $out);
if (is_array($out[1]) && !empty($out[1])) {
$out = array_unique($out[1]);
foreach ($out as $k => $v) {
if ($out[1][$k] == '#') {
continue;
}
$v = self::url_check($v, $url, $config);
$results = self::get_content($v, $config, 1);
if (!in_array($results['content'], $tmp)) {
$tmp[] = $results['content'];
}
}
}
}
$data['content'] = $config['content_page'] == 1 ? implode('[page]', $tmp) : implode('', $tmp);
}
if ($page == 0) {
//.........這裏部分代碼省略.........