本文整理汇总了PHP中phpQuery::newDocumentHTML方法的典型用法代码示例。如果您正苦于以下问题:PHP phpQuery::newDocumentHTML方法的具体用法?PHP phpQuery::newDocumentHTML怎么用?PHP phpQuery::newDocumentHTML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpQuery
的用法示例。
在下文中一共展示了phpQuery::newDocumentHTML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hyphenate
public static function hyphenate($strBuffer)
{
global $objPage;
$arrSkipPages = \Config::get('hyphenator_skipPages');
if (is_array($arrSkipPages) && in_array($objPage->id, $arrSkipPages)) {
return $strBuffer;
}
$o = new \Org\Heigl\Hyphenator\Options();
$o->setHyphen(\Config::get('hyphenator_hyphen'))->setDefaultLocale(static::getLocaleFromLanguage($objPage->language))->setRightMin(\Config::get('hyphenator_rightMin'))->setLeftMin(\Config::get('hyphenator_leftMin'))->setWordMin(\Config::get('hyphenator_wordMin'))->setFilters(\Config::get('hyphenator_filter'))->setQuality(\Config::get('hyphenator_quality'))->setTokenizers(\Config::get('hyphenator_tokenizers'));
$h = new \Org\Heigl\Hyphenator\Hyphenator();
$h->setOptions($o);
$doc = \phpQuery::newDocumentHTML($strBuffer);
foreach (pq('body')->find(\Config::get('hyphenator_tags')) as $n => $item) {
$strText = pq($item)->html();
// ignore html tags, otherwise ­ will be added to links for example
if ($strText != strip_tags($strText)) {
continue;
}
$strText = str_replace('­', '', $strText);
// remove manual ­ html entities before
$strText = $h->hyphenate($strText);
if (is_array($strText)) {
$strText = current($strText);
}
pq($item)->html($strText);
}
return $doc->htmlOuter();
}
示例2: getAllData
public function getAllData()
{
$url = $this->getWebsiteUrl();
$parser = new Parser();
$html = $parser->getHtml($url);
phpQuery::newDocumentHTML($html);
$data = array();
$data['logo'] = $this->getLogo();
$data['sitename'] = "Sulekha.com";
foreach (pq(".box") as $item) {
$class_Discount_bg = pq($item)->find(".dealimgst");
$href = pq($class_Discount_bg)->find("a")->attr("href");
$href = 'http://deals.sulekha.com' . $href;
$actual_price = trim(pq($item)->find(".dlpristrk")->text());
$actual_price = (int) preg_replace('~\\D~', '', $actual_price);
$img_src = pq($class_Discount_bg)->find("img")->attr("src");
$price = trim(pq($item)->find(".hgtlgtorg")->text());
$price = (int) preg_replace('~\\D~', '', $price);
$off_percent = $actual_price - $price;
$off_percent = number_format($off_percent) . "/-";
$price = number_format($price) . "/-";
$name = trim(pq($item)->find(".deallstit>a")->text());
//$time_left = pq($item)->find(".countdown_row")->text();
$data[] = array('name' => $name, 'href' => $href, 'price' => 'Rs.' . $price, 'image' => $img_src, 'off' => 'Rs.' . $off_percent);
}
return $data;
}
示例3: process
function process() {
if (!$this->processed) {
$this->processed = true;
$this->phpQueryDocument = phpQuery::newDocumentHTML($this->content);
phpQuery::selectDocument($this->phpQueryDocument);
}
}
示例4: search_query
function search_query($kw)
{
$wf = new Workflows();
$url = 'http://www.bilibili.tv/search?keyword=' . urlencode($kw) . '&orderby=&formsubmit=';
$content = $wf->request($url, array(CURLOPT_ENCODING => 1));
$doc = phpQuery::newDocumentHTML($content);
$list = $doc->find('li.l');
$i = 0;
foreach ($list as $item) {
$link = pq($item)->children('a:first')->attr('href');
if (strpos($link, 'http') !== 0) {
$link = 'http://www.bilibili.tv' . $link;
}
$info = pq($item)->find('div.info > i');
$author = pq($item)->find('a.upper:first')->text();
$view = $info->eq(0)->text();
$comment = $info->eq(1)->text();
$bullet = $info->eq(2)->text();
$save = $info->eq(3)->text();
$date = $info->eq(4)->text();
$subtitle = 'UP主:' . $author . ' 播放:' . $view . ' 评论:' . $comment . ' 弹幕:' . $bullet . ' 收藏:' . $save . ' 日期:' . $date;
$wf->result($i, $link, pq($item)->find('div.t:first')->text(), $subtitle, 'icon.png', 'yes');
$i++;
}
if (count($wf->results()) == 0) {
$wf->result('0', $url, '在bilibili.tv中搜索', $kw, 'icon.png', 'yes');
}
return $wf->toxml();
}
示例5: __construct
public function __construct($content, $params = [])
{
$this->dom = \phpQuery::newDocumentHTML($content);
foreach ($params as $attribute => $value) {
$this->{$attribute} = $value;
}
}
示例6: first_image
public function first_image($htmldata)
{
$pq = phpQuery::newDocumentHTML($htmldata);
$img = $pq->find('img:first');
$src = $img->attr('src');
return $src;
}
示例7: addBackendAdminMenu
public function addBackendAdminMenu($strBuffer, $strTemplate)
{
if ($strTemplate != 'be_main' || !\BackendUser::getInstance()->isAdmin) {
return $strBuffer;
}
// replace the scripts before processing -> https://code.google.com/archive/p/phpquery/issues/212
$arrScripts = StringUtil::replaceScripts($strBuffer);
$objDoc = \phpQuery::newDocumentHTML($arrScripts['content']);
$objMenu = new BackendTemplate($this->strTemplate);
$arrActions = array();
$arrActiveActions = deserialize(\Config::get('backendAdminMenuActiveActions'), true);
foreach (empty($arrActiveActions) ? array_keys(\Config::get('backendAdminMenuActions')) : $arrActiveActions as $strAction) {
$arrActionData = $GLOBALS['TL_CONFIG']['backendAdminMenuActions'][$strAction];
$objAction = new BackendTemplate($this->strEntryTemplate);
$objAction->setData($arrActionData);
// href = callback?
if (is_array($arrActionData['href']) || is_callable($arrActionData['href'])) {
$strClass = $arrActionData['href'][0];
$strMethod = $arrActionData['href'][1];
$objInstance = \Controller::importStatic($strClass);
$objAction->href = $objInstance->{$strMethod}();
}
$objAction->class = $strAction;
$arrActions[] = $objAction->parse();
}
$objMenu->actions = $arrActions;
$objDoc['#tmenu']->prepend($objMenu->parse());
$strBuffer = StringUtil::unreplaceScripts($objDoc->htmlOuter(), $arrScripts['scripts']);
// avoid double escapings introduced by phpquery :-(
$strBuffer = preg_replace('@&([^;]{2,4};)@i', '&$1', $strBuffer);
return $strBuffer;
}
示例8: parse_archive
public function parse_archive(Archive $archive)
{
if ($archive->cover_mode) {
return [$this->get_image_by_cover($archive->cover)];
}
$result = curl($archive->url, curl_options($this->domain));
$archivePQ = \phpQuery::newDocumentHTML($result['data']);
$content = $archivePQ['#content'];
$title = $content['.entry-title']->html();
$imgs = $content['.entry-content']->html();
if (preg_match_all('#' . $this->domain . 'wp-content/[^"]*#', $imgs, $matches)) {
$archive->images = array_merge(array_unique($matches[0]));
}
if (!$archive->images) {
$title = $content['.main-title']->html();
$imgs = $content['.main-body']->html();
if (preg_match_all('#<a[^>]+href="(' . $this->domain . 'wp-content/[^"]*)">#', $imgs, $matches)) {
$archive->images = array_merge(array_unique($matches[1]));
}
}
if (strtolower($this->charset) != strtolower($GLOBALS['app_config']['charset'])) {
$archive->title = iconv(strtoupper($this->charset), strtoupper($GLOBALS['app_config']['charset']) . '//IGNORE', $title);
}
$archive->title = $title;
}
示例9: getAllSubCategories
function getAllSubCategories($filename)
{
$categories = unserialize(file_get_contents($filename));
echo "---- run getAllSubCategories() ----\n\r";
foreach ($categories as $j => $category) {
if ($category['childrens']) {
foreach ($category['childrens'] as $k => $children) {
echo "---- crawling childrens for {$children['name']} ----\n\r";
$doc = phpQuery::newDocumentHTML(fetch('http://www.walmart.com' . $children['link']));
phpQuery::selectDocument($doc);
foreach (pq('.shop-by-category li') as $el) {
echo "---- " . pq($el)->find('a')->attr('href') . "} ----\n\r";
$childrens[] = array('name' => pq($el)->find('a')->data('name'), 'link' => pq($el)->find('a')->attr('href'));
}
$categories[$j]['childrens'][$k]['childrens'] = $childrens;
}
}
}
echo "---- creating deparment file ----\n\r";
$file = fopen($filename, 'w+');
echo "---- writing deparment file ----\n\r";
fputs($file, serialize($categories));
echo "---- closing deparment file ----\n\r";
fclose($file);
}
示例10: service
function service($nik)
{
$default = ['wilayah_id' => '0', 'g-recaptcha-response' => '000', 'cmd' => 'Cari.', 'page' => '', 'nik_global' => $nik];
$params = $default;
$client = new GuzzleHttp\Client();
$res = $client->request('POST', 'http://data.kpu.go.id/ss8.php', ['form_params' => $params]);
$html = $res->getBody();
$startsAt = strpos($html, '<body onload="loadPage()">') + strlen('<body onload="loadPage()">');
$endsAt = strpos($html, '</body>', $startsAt);
$result = substr($html, $startsAt, $endsAt - $startsAt);
// return $html;
$dom = phpQuery::newDocumentHTML($result);
// return $dom;
$result = [];
foreach (pq('div.form') as $content) {
$key = snake(preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', rtrim(trim(pq($content)->find('.label')->eq(0)->html()), ':')));
$value = preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', rtrim(trim(pq($content)->find('.field')->eq(0)->html()), ':'));
if (empty($key)) {
continue;
}
$result[$key] = $value;
}
if (!empty($result)) {
echo json_encode(['success' => true, 'message' => 'Success', 'data' => $result]);
} else {
http_response_code(400);
echo json_encode(['success' => false, 'message' => 'Data tidak ditemukan']);
}
}
示例11: getProducts
static function getProducts()
{
$products = pq(self::$productsQuery);
$productData = array();
foreach ($products->elements as $good) {
$product_links[$good->textContent] = $good->getAttribute('href');
}
foreach ($product_links as $sku => $link) {
$html = file_get_contents(self::$srcUrl . $link);
$url = parse_url($link);
if (isset($url['query'])) {
parse_str($url['query'], $params);
$cat = isset($params['cat_id']) ? $params['cat_id'] : 0;
$vendor = isset($params['vendor_id']) ? $params['vendor_id'] : 0;
}
phpQuery::newDocumentHTML($html, self::$encoding);
$product = new stdClass();
$product->model = $sku;
$product->sku = $sku;
$product->name = self::getProductName();
$product->specs = self::getProductSpecs();
$product->img = self::getProductImage();
$product->cat = $cat;
$product->vendor = $vendor;
$productData[] = $product;
}
return $productData;
}
示例12: detectPageType
/**
* @param string $pageHtml
* @param string $link
* @return string
*/
public function detectPageType($pageHtml, $link)
{
require_once './vendors/phpQuery.php';
$doc = phpQuery::newDocumentHTML($pageHtml);
$item = $doc->get('#fw_post_wrap');
if (preg_match("/id([0-9]+)/", $link, $matches)) {
return 'user';
}
if (preg_match("/wall-?([0-9_]+)/", $link, $matches)) {
return 'wall';
}
if (preg_match("/public([0-9]+)/", $link, $matches)) {
return 'public';
}
if (preg_match("/photo-?([0-9_]+)/", $link, $matches)) {
return 'photo';
}
if (!empty($item)) {
return "post";
}
$item = $doc['#group'];
if (!empty($item)) {
return "group";
}
$item = $doc['#public'];
if (!empty($item)) {
return 'public';
}
}
示例13: actionKNet
public function actionKNet()
{
// создаем экземпляр класса
$client = new Client();
// отправляем запрос к странице Яндекса
$res = $client->request('GET', 'http://kondratiev.net/loader.php?getPage=gallery');
// получаем данные между открывающим и закрывающим тегами body
$body = $res->getBody();
// подключаем phpQuery
$document = \phpQuery::newDocumentHTML($body);
// получаем список новостей
//$news = $document->find("ul.b-news-list");
$kSite = $document->find(".widePhotoGallery");
//d(count($kSite));
// выполняем проход циклом по списку
foreach ($kSite as $elem) {
//pq аналог $ в jQuery
$pq = pq($elem);
// удалим первую новость в списке
//$pq->find('li.list__item:first')->remove();
// выполним поиск в скиске ссылок
//$tags = $pq->find('li.list__item a');
// добавим ковычки в начало и в конец предложения
//$tags->append('" ')->prepend(' "'); //
// добавим свой класс к последней новости списка
$pq->find('div.widePhoto')->addClass('display-block');
}
// вывод списка новостей яндекса с главной страницы в представление
return $this->render('k-net', ['kSite' => $kSite]);
}
示例14: start_el
function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
{
// append next menu element to $output
parent::start_el($output, $object, $depth, $args, $current_object_id);
// now let's add a custom form field
if (!class_exists('phpQuery')) {
// load phpQuery at the last moment, to minimise chance of conflicts (ok, it's probably a bit too defensive)
require_once 'phpQuery-onefile.php';
}
$_doc = phpQuery::newDocumentHTML($output);
$_li = phpQuery::pq('li.menu-item:last');
// ":last" is important, because $output will contain all the menu elements before current element
// if the last <li>'s id attribute doesn't match $item->ID something is very wrong, don't do anything
// just a safety, should never happen...
$menu_item_id = str_replace('menu-item-', '', $_li->attr('id'));
if ($menu_item_id != $object->ID) {
return;
}
// fetch previously saved meta for the post (menu_item is just a post type)
$curr_bg = esc_attr(get_post_meta($menu_item_id, 'snpshpwp_menu_item_bg', TRUE));
$curr_bg_pos = esc_attr(get_post_meta($menu_item_id, 'snpshpwp_menu_item_bg_pos', TRUE));
$curr_upldr = '<span class="button media_upload_button" id="snpshpwp_upload_' . $menu_item_id . '">' . __('Upload', 'snpshpwp') . '</span>';
// by means of phpQuery magic, inject a new input field
$_li->find('a.item-delete')->before("\n\t\t\t\t\t<p class='snpshpwp_menu_item_bg description description-thin'>\n\t\t\t\t\t<label for='snpshpwp_menu_item_bg_{$menu_item_id}'>" . __('Background image', 'snpshpwp') . "<br/>\n\t\t\t\t\t<input type='text' value='{$curr_bg}' name='snpshpwp_menu_item_bg_{$menu_item_id}' /><br/>\n\t\t\t\t\t</label>\n\t\t\t\t\t{$curr_upldr}\n\t\t\t\t\t</p>\n\t\t\t\t\t<p class='snpshpwp_menu_item_bg_pos description description-thin'>\n\t\t\t\t\t<label for='snpshpwp_menu_item_bg_{$menu_item_id}'>" . __('Background orientation', 'snpshpwp') . "<br/>\n\t\t\t\t\t<select name='snpshpwp_menu_item_bg_pos_{$menu_item_id}'>\n\t\t\t\t\t\t<option value='left-landscape'" . ($curr_bg_pos == 'left-landscape' ? ' selected' : '') . ">" . __('Left Landscape', 'snpshpwp') . "</option>\n\t\t\t\t\t\t<option value='left-portraid'" . ($curr_bg_pos == 'left-portraid' ? ' selected' : '') . ">" . __('Left Portraid', 'snpshpwp') . "</option>\n\t\t\t\t\t\t<option value='right-landscape'" . ($curr_bg_pos == 'right-landscape' ? ' selected' : '') . ">" . __('Right Landscape', 'snpshpwp') . "</option>\n\t\t\t\t\t\t<option value='right-portraid'" . ($curr_bg_pos == 'right-portraid' ? ' selected' : '') . ">" . __('Right Portraid', 'snpshpwp') . "</option>\n\t\t\t\t\t\t<option value='pattern-repeat'" . ($curr_bg_pos == 'pattern-repeat' ? ' selected' : '') . ">" . __('Pattern', 'snpshpwp') . "</option>\n\t\t\t\t\t\t<option value='framed-full'" . ($curr_bg_pos == 'framed-full' ? ' selected' : '') . ">" . __('Framed', 'snpshpwp') . "</option>\n\t\t\t\t\t</select>\n\t\t\t\t\t</label>\n\t\t\t\t\t</p>\n\t\t\t\t\t");
// swap the $output
$output = $_doc->html();
}
示例15: theContent
function theContent($content)
{
$doc = phpQuery::newDocumentHTML($content);
phpQuery::selectDocument($doc);
foreach (pq('a') as $link) {
$linkurl = pq($link)->attr('href');
$linkHostname = $this->getUrlHostname($linkurl);
if ($linkHostname != FALSE) {
if (!in_array($linkHostname, $this->blockedDomains)) {
$linkHash = md5($linkurl);
$query = "SELECT * FROM {$this->tableBitlyExternal} WHERE id='{$linkHash}'LIMIT 1;";
$linkData = $this->db->get_row($query, ARRAY_A);
if (empty($linkData)) {
$bitly = new Bitly($this->bitlyUsername, $this->bitlyApikey);
$shortURL = $bitly->shorten($linkurl);
$shortURLData = get_object_vars($bitly->getData());
if (!empty($shortURLData)) {
$linkData = array('id' => $linkHash, 'url' => $linkurl, 'short_url' => $shortURLData['shortUrl'], 'hash' => $shortURLData['userHash'], 'created' => current_time('mysql'));
$this->db->insert($this->tableBitlyExternal, $linkData);
}
}
if (!empty($linkData)) {
pq($link)->attr('href', $linkData['short_url']);
}
}
}
}
return $doc->htmlOuter();
}