ok
This commit is contained in:
parent
02c4c93ee5
commit
8bd07f5fbb
@ -21,7 +21,6 @@ class QueryList
|
|||||||
protected $document;
|
protected $document;
|
||||||
protected $rules;
|
protected $rules;
|
||||||
protected $range = null;
|
protected $range = null;
|
||||||
protected $isRemoveHead = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QueryList constructor.
|
* QueryList constructor.
|
||||||
@ -68,19 +67,20 @@ class QueryList
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeHead($isRemoveHead = true)
|
public function removeHead()
|
||||||
{
|
{
|
||||||
$this->isRemoveHead = $isRemoveHead;
|
$html = preg_replace('/<head.+?>.+<\/head>/is','<head></head>',$this->html);
|
||||||
|
$this->setHtml($html);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function query($callback = null)
|
public function query($callback = null)
|
||||||
{
|
{
|
||||||
$data = $this->_getList();
|
$data = $this->getList();
|
||||||
return is_null($callback)?$data:$data->map($callback);
|
return is_null($callback)?$data:$data->map($callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _getList()
|
protected function getList()
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
$document = $this->document;
|
$document = $this->document;
|
||||||
@ -94,10 +94,10 @@ class QueryList
|
|||||||
|
|
||||||
switch ($reg_value[1]) {
|
switch ($reg_value[1]) {
|
||||||
case 'text':
|
case 'text':
|
||||||
$data[$i][$key] = $this->_allowTags(pq($iobj)->html(),$tags);
|
$data[$i][$key] = $this->allowTags(pq($iobj)->html(),$tags);
|
||||||
break;
|
break;
|
||||||
case 'html':
|
case 'html':
|
||||||
$data[$i][$key] = $this->_stripTags(pq($iobj)->html(),$tags);
|
$data[$i][$key] = $this->stripTags(pq($iobj)->html(),$tags);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$data[$i][$key] = pq($iobj)->attr($reg_value[1]);
|
$data[$i][$key] = pq($iobj)->attr($reg_value[1]);
|
||||||
@ -120,10 +120,10 @@ class QueryList
|
|||||||
foreach ($lobj as $item) {
|
foreach ($lobj as $item) {
|
||||||
switch ($reg_value[1]) {
|
switch ($reg_value[1]) {
|
||||||
case 'text':
|
case 'text':
|
||||||
$data[$i][$key] = $this->_allowTags(pq($item)->html(),$tags);
|
$data[$i][$key] = $this->allowTags(pq($item)->html(),$tags);
|
||||||
break;
|
break;
|
||||||
case 'html':
|
case 'html':
|
||||||
$data[$i][$key] = $this->_stripTags(pq($item)->html(),$tags);
|
$data[$i][$key] = $this->stripTags(pq($item)->html(),$tags);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$data[$i][$key] = pq($item)->attr($reg_value[1]);
|
$data[$i][$key] = pq($item)->attr($reg_value[1]);
|
||||||
@ -148,10 +148,10 @@ class QueryList
|
|||||||
* @param string $tags_str 多个标签名之间用空格隔开
|
* @param string $tags_str 多个标签名之间用空格隔开
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function _stripTags($html,$tags_str)
|
protected function stripTags($html,$tags_str)
|
||||||
{
|
{
|
||||||
$tagsArr = $this->_tag($tags_str);
|
$tagsArr = $this->tag($tags_str);
|
||||||
$html = $this->_removeTags($html,$tagsArr[1]);
|
$html = $this->removeTags($html,$tagsArr[1]);
|
||||||
$p = array();
|
$p = array();
|
||||||
foreach ($tagsArr[0] as $tag) {
|
foreach ($tagsArr[0] as $tag) {
|
||||||
$p[]="/(<(?:\/".$tag."|".$tag.")[^>]*>)/i";
|
$p[]="/(<(?:\/".$tag."|".$tag.")[^>]*>)/i";
|
||||||
@ -166,10 +166,10 @@ class QueryList
|
|||||||
* @param string $tags_str 多个标签名之间用空格隔开
|
* @param string $tags_str 多个标签名之间用空格隔开
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function _allowTags($html,$tags_str)
|
protected function allowTags($html,$tags_str)
|
||||||
{
|
{
|
||||||
$tagsArr = $this->_tag($tags_str);
|
$tagsArr = $this->tag($tags_str);
|
||||||
$html = $this->_removeTags($html,$tagsArr[1]);
|
$html = $this->removeTags($html,$tagsArr[1]);
|
||||||
$allow = '';
|
$allow = '';
|
||||||
foreach ($tagsArr[0] as $tag) {
|
foreach ($tagsArr[0] as $tag) {
|
||||||
$allow .= "<$tag> ";
|
$allow .= "<$tag> ";
|
||||||
@ -177,7 +177,7 @@ class QueryList
|
|||||||
return strip_tags(trim($html),$allow);
|
return strip_tags(trim($html),$allow);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _tag($tags_str)
|
protected function tag($tags_str)
|
||||||
{
|
{
|
||||||
$tagArr = preg_split("/\s+/",$tags_str,-1,PREG_SPLIT_NO_EMPTY);
|
$tagArr = preg_split("/\s+/",$tags_str,-1,PREG_SPLIT_NO_EMPTY);
|
||||||
$tags = array(array(),array());
|
$tags = array(array(),array());
|
||||||
@ -199,7 +199,7 @@ class QueryList
|
|||||||
* @param array $tags 标签数组
|
* @param array $tags 标签数组
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function _removeTags($html,$tags)
|
protected function removeTags($html,$tags)
|
||||||
{
|
{
|
||||||
$tag_str = '';
|
$tag_str = '';
|
||||||
if(count($tags))
|
if(count($tags))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user