hyperf框架QueryList(phpQuery)

  • Post author:
  • Post category:php


安装QueryList,使用Composer安装

执行Composer安装命令:

composer require jaeger/querylist:V3.2.1

在项目中使用QueryList   (use QL\QueryList)直接引用

<?php

declare(strict_types = 1);
namespace App\Controller;

use Hyperf\View\RenderInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use QL\QueryList;
/**
 * @AutoController
 */
class WelcomeController
{
    public function abc(){

        $content = '<p><span style="color: rgb(68, 68, 68); background-color: rgb(255,255,255); font-size: 15px;">近日,</span><span style="color: rgb(0, 112, 192); background-color: rgb(255, 255, 255); font-size: 15px;"><strong>《深圳市20大先进制造业园区空间布局规划》</strong></span><span style="color: rgb(68, 68, 68); background-color: rgb(255, 255, 255); font-size: 15px;">出炉,按照集中连片、产住分离的原则,在宝安、龙岗、龙华、坪山、光明、盐田、大鹏新区、深汕特别合作区合理划定先进制造业园区,总规划用地面积约300平方公里,按照启动区、拓展区、储备区有计划释放工业用地面积约60平方公里。</span></p><p><img src="uploads/2022-08/155b40d3e9690cd7ef9895d7ac9f978f.jpg" alt="测试" data-href="111" style=""/></p>';
        \phpQuery::newDocumentHTML($content);
        $pq = pq(null);
        $images = $pq->find("img");
        if ($images->length) {
            foreach ($images as $img) {
                $img    = pq($img);
                $imgSrc = $img->attr("src");
                $img->attr("src", 'https://mxxxx.com/'.$imgSrc);
            }
        }
        $content = $pq->html();
        \phpQuery::$documents = null;
        return json_encode(['c'=>$content]);
    }
}

QueryList文档地址

QueryList V3 中文文档



版权声明:本文为qq_33212312原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。