本文整理汇总了PHP中phpQuery::each方法的典型用法代码示例。如果您正苦于以下问题:PHP phpQuery::each方法的具体用法?PHP phpQuery::each怎么用?PHP phpQuery::each使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpQuery
的用法示例。
在下文中一共展示了phpQuery::each方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadWP
public function loadWP()
{
if (file_exists($this->wpPath)) {
phpQuery::newDocumentFileXML($this->wpPath);
$itemArr = pq("channel item");
phpQuery::each($itemArr, "WordPress::parseWpItem");
} else {
$this->_error = "wordpress.xml文件不存在";
}
}
示例2: loadWP
public function loadWP()
{
$fag = false;
if (file_exists($this->wpPath)) {
phpQuery::newDocumentFileXML($this->wpPath);
$itemArr = pq("channel item");
if ($itemArr->size() > 0) {
phpQuery::each($itemArr, "WordPress::parseWpItem");
$this->_error = "finish!";
$fag = true;
} else {
$this->_error = "not detected data!";
}
} else {
$this->_error = "wordpress.xml file is not exists!";
}
return $fag;
}
示例3: elseif
}
} elseif (isset($Rule['Selector'])) {
phpQuery::each(pq($Rule['Selector']), function ($Index, $Element) use(&$Data, $Key, $Rule, $Call) {
F::Log('Selector fired ' . $Rule['Selector'], LOG_NOTICE);
if (isset($Rule['Text'])) {
$Value = preg_replace('/\\s{2,}|\\s{2,}$/Ssm', PHP_EOL, pq($Element)->text());
} elseif (isset($Rule['Attr'])) {
$Value = preg_replace('/\\s{2,}|\\s{2,}$/Ssm', PHP_EOL, pq($Element)->attr($Rule['Attr']));
} else {
$Value = preg_replace('/\\s{2,}|\\s{2,}$/Ssm', PHP_EOL, pq($Element)->html());
}
if (empty($Value)) {
F::Log($Key . ' not defined', LOG_INFO);
} else {
F::Log($Key . '.' . $Index . ' is ' . $Value, LOG_INFO);
if (isset($Rule['Regex'])) {
if (preg_match($Rule['Regex'], $Value, $Pockets)) {
if (isset($Pockets[1])) {
$Value = $Pockets[1];
}
} else {
$Value = null;
}
}
$Value = trim($Value);
if (!empty($Value)) {
$Data = F::Dot($Data, $Key . '.' . $Index, $Value);
}
}
});
} elseif (isset($Rule['Regex'])) {
if (preg_match($Rule['Regex'], $Call['Markup'], $Pockets)) {
示例4: setFn
setFn('Get Links', function ($Call) {
phpQuery::newDocumentHTML($Call['Body']);
$URLs = [];
phpQuery::each(pq('a'), function ($Index, $Element) use(&$Call, &$URLs) {
$URL = parse_url($Element->getAttribute('href'));
if (!isset($URL['scheme']) || $URL['scheme'] == 'http') {
if (isset($URL['host']) && 'http://' . $URL['host'] != $Call['Host']) {
$Decision = false;
} else {
$Decision = true;
}
$URL = isset($URL['path']) ? $URL['path'] : '';
if (in_array($URL, $Call['Processed'])) {
$Decision = false;
}
if (isset($Call['White']) && !preg_match($Call['White'], $URL)) {
$Decision = false;
}
if (isset($Call['Black']) && preg_match($Call['Black'], $URL)) {
$Decision = false;
}
if (substr($URL, 0, 1) != '/') {
$URL = '/' . $URL;
}
if ($Decision) {
$URLs[] = $URL;
}
}
});
phpQuery::unloadDocuments();
return $URLs;
});
示例5: setFn
<?php
/* Codeine
* @author bergstein@trickyplan.com
* @description
* @package Codeine
* @version 7.x
*/
include_once 'phpQuery/phpQuery.php';
setFn('Do', function ($Call) {
return F::Run(null, $Call['HTTP']['Method'], $Call);
});
setFn('GET', function ($Call) {
$Call['Layouts'][] = ['Scope' => 'Parser', 'ID' => 'Spider'];
return $Call;
});
setFn('POST', function ($Call) {
foreach ($Call['Spider']['Tasks'] as $Name => $Task) {
$Result = F::Live($Task['Backend'], ['Where' => ['ID' => $Task['URL']]]);
$Data = [];
$Result = array_pop($Result);
phpQuery::newDocumentHTML($Result);
phpQuery::each(pq($Task['Selector']), function ($Index, $Element) use(&$Data) {
$Data[$Index] = pq($Element)->attr('href');
});
foreach ($Data as $Row) {
F::Run('Code.Run.Delayed', 'Run', ['Run' => ['Service' => 'Parser.URL', 'Method' => 'Parse', 'Call' => ['URL' => $Task['Host'] . $Row]]]);
}
}
return $Call;
});
示例6: setFn
setFn('Spider', function ($Call) {
phpQuery::newDocumentHTML($Call['Body']);
$Call['NL'] = 0;
phpQuery::each(pq('a'), function ($Index, $Element) use(&$Call) {
$URL = parse_url($Element->getAttribute('href'));
if (isset($URL['host']) && $URL['host'] != $Call['Host']) {
$Decision = false;
} else {
$Decision = true;
}
$URL = (isset($URL['path']) ? $URL['path'] : '') . (isset($URL['query']) ? '?' . $URL['query'] : '');
if (in_array($URL, $Call['Processed']) or in_array($URL, $Call['URLs'])) {
$Decision = false;
} elseif (isset($Call['Spider']['White']) && !preg_match('@' . $Call['Spider']['White'] . '@', $URL)) {
$Decision = false;
} elseif (isset($Call['Spider']['Black']) && preg_match('@' . $Call['Spider']['Black'] . '@', $URL)) {
$Decision = false;
} elseif (file_exists(F::Run(null, 'Select Filename', $Call, ['URL' => $URL]))) {
$Decision = false;
}
if (substr($URL, 0, 1) != '/') {
$URL = '/' . $URL;
}
if ($Decision) {
$Call['URLs'][] = 'http://' . $Call['Host'] . $URL;
$Call['NL']++;
}
});
phpQuery::unloadDocuments();
F::Log('New links founded ' . $Call['NL'], LOG_WARNING);
return $Call;