本文整理汇总了PHP中pq函数的典型用法代码示例。如果您正苦于以下问题:PHP pq函数的具体用法?PHP pq怎么用?PHP pq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pq函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readCoinInformation
protected function readCoinInformation($pq_tr)
{
$coin_data = array();
$img_indexes = array('obverse', 'reverse');
$pq_td = $pq_tr->find('td');
$as = $pq_td->find('a');
foreach ($as as $index => $a) {
$pq_a = pq($a);
switch ($index) {
case 0:
case 1:
$img_url = $this->fixImageUrl($pq_a->find('img')->attr('src'));
$coin_data[$img_indexes[$index]] = $img_url;
break;
case 2:
$coin_data['name'] = $pq_a->text();
$pq_td->find('span, a, br')->remove();
$chr = chr(194) . chr(160);
$km = trim(str_replace($chr, ' ', $pq_td->text()));
$km = trim(str_replace('Total:', '', $km));
$coin_data['km'] = $km;
break;
}
}
return $coin_data;
}
示例2: run
public function run()
{
$content = ob_get_clean();
$formatted = phpQuery::newDocument($content);
$imageNodes = pq('img');
foreach ($imageNodes as $imNode) {
$imNode = pq($imNode);
$imPath = $imNode->attr('src');
$thumbPath = $this->thumbsDir . '/' . basename($imPath);
//$thumbPath = dirname($imPath).'/thumbs/'.basename($imPath);
// Create thumbnail if not exists
if (!file_exists($thumbPath)) {
$imgObj = Yii::app()->simpleImage->load($imPath);
if (!isset($this->thumbHeight)) {
$imgObj->resizeToWidth($this->thumbWidth);
} else {
$imgObj->resize($this->thumbWidth, $this->thumbHeight);
}
$imgObj->save($thumbPath);
}
$imNode->wrap('<a href="' . $imPath . '" rel="gallery"></a>');
$imNode->attr('src', Yii::app()->request->baseUrl . DIRECTORY_SEPARATOR . $thumbPath);
}
echo $formatted;
}
示例3: 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();
}
示例4: getHorario
function getHorario() {
if($this->horario != null) return $this->horario;
parent::process();
$dotw = array('Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado');
$this->horario = array('Lunes' => array()
, 'Martes' => array()
, 'Miércoles' => array()
, 'Jueves' => array()
, 'Viernes' => array()
, 'Sábado' => array());
foreach(pq('td.dia') as $day => $bloques) {
foreach(pq('div', $bloques) as $tmp_bloque) {
$bloque = new stdClass();
$bloque->codigo = pq('a', $tmp_bloque)->html();
list(,$tmp_tipo,, $tmp_horario) = pq($tmp_bloque)->contents()->elements;
$bloque->tipo = trim(pq($tmp_tipo)->text());
list($bloque->sala, $bloque->hora) = explode(chr(194).chr(160), pq($tmp_horario)->text());
$this->horario[$dotw[$day]][] = $bloque;
}
}
return $this->horario;
}
示例5: get_data
public function get_data()
{
if (!class_exists('phpQuery')) {
include dirname(__FILE__) . '/phpQuery.php';
}
$response = wp_remote_get($this->url . '/tags');
if (is_wp_error($response)) {
return false;
}
phpQuery::newDocument($response['body']);
$version = false;
$zip_url = false;
foreach (pq('table.tags a.name') as $tag) {
$tag = pq($tag);
if (version_compare($tag->text(), $version, '>=')) {
$href = $tag->attr('href');
$commit = substr($href, strrpos($href, '/') + 1);
$zip_url = $this->url . '/snapshot/' . $commit . '.zip';
$version = $tag->text();
$updated_at = $tag->parent()->prev()->text();
}
}
$this->new_version = $version;
$this->zip_url = $zip_url;
$this->updated_at = date('Y-m-d', strtotime($updated_at));
$this->description = pq('div.page_footer_text')->text();
}
示例6: success
public function success($response)
{
$pq = phpQuery::newDocument($response);
foreach ($this->calls as $k => $r) {
// check if method exists
if (!method_exists(get_class($pq), $r['method'])) {
throw new Exception("Method '{$r['method']}' not implemented in phpQuery, sorry...");
// execute method
} else {
$pq = call_user_func_array(array($pq, $r['method']), $r['arguments']);
}
}
if (!isset($this->options['dataType'])) {
$this->options['dataType'] = '';
}
switch (strtolower($this->options['dataType'])) {
case 'json':
if ($pq instanceof PHPQUERYOBJECT) {
$results = array();
foreach ($pq as $node) {
$results[] = pq($node)->htmlOuter();
}
print phpQuery::toJSON($results);
} else {
print phpQuery::toJSON($pq);
}
break;
default:
print $pq;
}
// output results
}
示例7: getList
protected function getList()
{
$this->data['list'] = array();
$ul = $this->q->find('#liste_echanges li');
if ($ul->count() == 0) {
return;
}
$years = $ul->find('ul li');
foreach ($years as $year) {
$pq_year = pq($year);
$html = trim($pq_year->html());
$year_txt = html_entity_decode(trim(strip_tags(substr($html, 0, strpos($html, ':')))));
$item = array('year' => $year_txt, 'users' => array());
$as = $pq_year->find('a');
foreach ($as as $a) {
$pq_a = pq($a);
$href = $pq_a->attr('href');
$user_name = $pq_a->text();
$ret = preg_match('|membre\\.php\\?id=([0-9]+)|', $href, $matches);
if ($ret == 1 && isset($matches[1])) {
$item['users'][] = array('id' => $matches[1], 'name' => $user_name);
}
}
$this->data['list'][] = $item;
}
}
示例8: getNovedades
function getNovedades() {
if($this->novedades != null) return $this->novedades;
parent::process();
$this->novedades = array();
foreach(pq('div.blog') as $item) {
$novedad = new stdClass();
$tmp_autor = pq('em', $item);
$tmp_autor_i = strpos($tmp_autor, '<a class');
$tmp_autor_f = strpos($tmp_autor, '</a>') + 4;
$novedad->texto = pq($item)->children('p');
foreach(pq('a', $novedad->texto) as $href) {
$href_url = pq($href)->attr('href');
if(substr($href_url, 0, 2) == 'r/')
pq($href)->attr('href', $this->url . $href_url);
}
foreach(pq('img', $novedad->texto) as $href) {
$img_src = pq($href)->attr('src');
if(substr($img_src, 0, 2) == 'r/')
pq($href)->attr('src', $this->url . $img_src);
}
$novedad->texto = mb_convert_encoding(pq($novedad->texto)->html(), 'UTF-8');
$novedad->titulo = trim(pq(pq($item)->children('h1'))->text());
$novedad->fecha = trim(substr($tmp_autor, $tmp_autor_f));
$novedad->autor = new stdClass();
$novedad->autor->nombre = pq(substr($tmp_autor, $tmp_autor_i, $tmp_autor_f - $tmp_autor_i + 1))->html();
$novedad->autor->avatar = pq('img')->attr('src');
$this->novedades[] = $novedad;
}
return $this->novedades;
}
示例9: elseif
public function &__get($key)
{
if (isset($this->data[$key])) {
return $this->data[$key];
} elseif (isset($this->data['organization'][$key])) {
return $this->data['organization'][$key];
} elseif (method_exists($this, '_load_' . $key)) {
$func = '_load_' . $key;
return $this->{$func}();
} elseif (isset($this->form_object)) {
switch ($key) {
case 'organization':
$this->data['organization']['id'] = pq('id')->text();
$this->data['organization']['short_name'] = pq('short_name')->text();
return $this->data['organization'];
case 'id':
$this->data['organization']['id'] = pq('id')->text();
return $this->data['organization']['id'];
case 'short_name':
$this->data['organization']['short_name'] = pq('short_name')->text();
return $this->data['organization']['short_name'];
default:
$this->data[$key] = pq($key)->text();
return $this->data[$key];
}
//end switch
}
//end elseif
return null;
}
示例10: getLinkContent
public function getLinkContent()
{
require_once './ThinkPHP/Library/Vendor/Collection/phpQuery.php';
$link = op_t(I('post.url'));
$content = get_content_by_url($link);
$charset = preg_match("/<meta.+?charset=[^\\w]?([-\\w]+)/i", $content, $temp) ? strtolower($temp[1]) : "utf-8";
\phpQuery::$defaultCharset = $charset;
\phpQuery::newDocument($content);
$title = pq("meta[name='title']")->attr('content');
if (empty($title)) {
$title = pq("title")->html();
}
$title = iconv($charset, "UTF-8", $title);
$keywords = pq("meta[name='keywords'],meta[name='Keywords']")->attr('content');
$description = pq("meta[name='description'],meta[name='Description']")->attr('content');
$url = parse_url($link);
$img = pq("img")->eq(0)->attr('src');
if (is_bool(strpos($img, 'http://'))) {
$img = 'http://' . $url['host'] . $img;
}
$title = text($title);
$description = text($description);
$keywords = text($keywords);
$return['title'] = $title;
$return['img'] = $img;
$return['description'] = empty($description) ? $title : $description;
$return['keywords'] = empty($keywords) ? $title : $keywords;
exit(json_encode($return));
}
示例11: Process
/**
* Process emoticons inside a string
* @since Version 3.10.0
* @param string|DOMDocument $string The HTML or text block to process
* @param boolean $doEmoticons Boolean flag for processing or skipping emoticons
* @return DOMDocument
*/
public static function Process($string, $doEmoticons = true)
{
if (!$doEmoticons) {
return $string;
}
$emojiOne = new EmojioneClient(new EmoticonsRuleset());
$emojiOne->ascii = true;
$string = $emojiOne->toImage($string);
$attr = "data-sceditor-emoticon";
$timer = Debug::getTimer();
if (is_string($string)) {
$string = phpQuery::newDocumentHTML($string);
}
//phpQuery::selectDocument($doc);
// Remove #tinymce and .mceContentBody tags
foreach (pq('img') as $e) {
if (pq($e)->attr($attr)) {
$emoticon = pq($e)->attr($attr);
if (strlen($emoticon) > 0) {
pq($e)->replaceWith(str_replace('\\"', "", $emoticon));
}
}
}
Debug::LogEvent(__METHOD__, $timer);
return $string;
}
示例12: RenderImpl
/**
* @see HtmlComponent
*/
public final function RenderImpl()
{
$tag = $this->getTag('table');
pq($tag)->append($this->renderHeader());
pq($tag)->append($this->renderData());
pq($tag)->append($this->renderFooter());
}
示例13: getNotas
function getNotas() {
if($this->cursos != null) return $this->cursos;
parent::process();
$this->cursos = array();
$identifier = null;
foreach(pq('table > *:not(thead)') as $bloques) {
if ($bloques->tagName == 'tr') {
if(!$identifier) {
$identifier = pq('td', $bloques)->text();
}
}
else {
$identifier = $identifier ? $identifier : '';
if (!isset($this->notas[$identifier])) $this->notas[$identifier] = array();
foreach(pq('tr', $bloques) as $tr) {
$curso = new stdClass();
$curso->id = pq('td:nth-child(3)', $tr)->html();
$curso->nombre = mb_convert_encoding(pq('td:nth-child(4) > a', $tr)->html(), 'UTF-8');
$curso->url = pq('td:nth-child(4) > a', $tr)->attr('href');
$curso->cargo = UcursosScrapper::toUserType(pq('td:nth-child(1) > img', $tr)->attr('title'));
$curso->institucion = new stdClass();
$curso->institucion->nombre = pq('td:nth-child(2) > img', $tr)->attr('title');
$curso->institucion->icono = pq('td:nth-child(2) > img', $tr)->attr('src');
$this->cursos[$identifier][] = $curso;
}
$identifier = null;
}
}
return $this->cursos;
}
示例14: createPost
private function createPost(\phpQueryObject $form)
{
$result = [];
foreach ($form->find('input, select, checkbox, textarea') as $input) {
$el = pq($input);
if (($value = $el->attr('example')) || ($value = $el->attr('value'))) {
$result[$el->attr('name')] = $value;
continue;
}
$value = $el->attr('example');
switch ($input->tagName) {
case 'input':
$this->addInput($el, $result, $value);
break;
case 'select':
$this->addSelect($el, $result, $value);
break;
case 'checkbox':
$this->addCheckbox($el, $result, $value);
break;
case 'textarea':
$this->addTextarea($el, $result, $value);
break;
}
}
return $result;
}
示例15: getData
/**
* Implements the getData method
*/
public function getData()
{
//request the url
$this->request(self::URL);
$title = pq('h1.summary:first');
return pq('a', $title)->text();
}