最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Mac中安装和使用composer安装php的库php-html-parser

Mac crifan 2211浏览 0评论

折腾:

【未解决】php中用正则过滤html中code中多余span标签

期间,看到:

https://github.com/paquettg/php-html-parser

中提到了,该php的库是建议用composer去安装

对此也就是:

如何才能使用上:

require 'vendor/autoload.php';

https://github.com/Masterminds/html5-php

如何使用composer

php composer

简介 | Composer 中文文档 | Composer 中文网

但是对于

https://github.com/paquettg/php-html-parser

如何写composer.json没解释

参考

https://github.com/Masterminds/html5-php

https://github.com/paquettg/php-html-parser/blob/master/composer.json

{
  "require": {
      "paquettg/php-html-parser": "2.0.2"
  }
}

https://packagist.org/packages/paquettg/php-html-parser

不知道对不对

Composer 中文网 / Packagist 中国全量镜像

基本用法 | Composer 中文文档 | Composer 中文网

去安装试试:

curl -sS https://getcomposer.org/installer | php

结果

curl -sS https://getcomposer.org/installer | php
<p>All settings correct for using Composer</p><p>Downloading...</p><p>The "https://getcomposer.org/download/1.8.6/composer.phar" file could not be downloaded: SSL: Connection reset by peer</p><p>failed to open stream: HTTP request failed! Retrying...</p><p>^C</p>

参考

https://docs.phpcomposer.com/00-intro.html

全局安装 (on OSX via homebrew)

去试试

➜  useHtmlLibParseEvernoteHtml brew update
^C%                                                                                                                     
➜  useHtmlLibParseEvernoteHtml 
➜  useHtmlLibParseEvernoteHtml brew tap josegonzalez/homebrew-php
==> Tapping josegonzalez/php
Cloning into '/usr/local/Homebrew/Library/Taps/josegonzalez/homebrew-php'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 0), reused 2 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
Tapped (33 files, 27.3KB).
➜  useHtmlLibParseEvernoteHtml brew tap homebrew/versions
Error: homebrew/versions was deprecated. This tap is now empty as all its formulae were migrated.
➜  useHtmlLibParseEvernoteHtml brew install php55-intl
Error: No available formula with the name "php55-intl" 
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow


Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
➜  useHtmlLibParseEvernoteHtml brew install josegonzalez/php/composer
Warning: Use composer instead of deprecated josegonzalez/php/composer
Warning: Use composer instead of deprecated josegonzalez/php/composer
==> Downloading https://getcomposer.org/download/1.8.5/composer.phar
#                                                                          1.7%

慢慢下载吧

不过从前面貌似看出是:

直接下载

https://getcomposer.org/download/1.8.6/composer.phar

或:

https://getcomposer.org/download/1.8.5/composer.phar

然后放到PATH的路径中,就可以了的感觉

➜  composer cp composer.phar /usr/local/bin
➜  composer which composer
composer not found
➜  composer ll -h
total 4352
-rw-r--r--@ 1 crifan  staff   1.8M  6 11 21:03 composer.phar
➜  composer ll /usr/local/bin/composer.phar
-rw-r--r--@ 1 crifan  admin   1.8M  7 23 22:50 /usr/local/bin/composer.phar

但是并不能直接运行

Composer三步曲:安装、使用、发布 – 滴水石穿 – SegmentFault 思否

直接改名为composer就好

➜  composer mv /usr/local/bin/composer.phar /usr/local/bin/composer
➜  composer ll /usr/local/bin/composer
-rw-r--r--@ 1 crifan  admin   1.8M  7 23 22:50 /usr/local/bin/composer
➜  composer which composer
composer not found
➜  composer /usr/local/bin/composer --version
zsh: permission denied: /usr/local/bin/composer
➜  composer chmod +x /usr/local/bin/composer
➜  composer ll /usr/local/bin/composer
-rwxr-xr-x@ 1 crifan  admin   1.8M  7 23 22:50 /usr/local/bin/composer
➜  composer /usr/local/bin/composer --version
Composer version 1.8.6 2019-06-11 15:03:05
➜  composer which composer
/usr/local/bin/composer
➜  composer composer --version
Composer version 1.8.6 2019-06-11 15:03:05

可见还需要手动加上可执行权限才行的。

再去试试安装php-html-parser库:

【已解决】Mac中composer install安装php的模块卡死在Updating dependencies including require-dev

然后再去看看如何使用

然后用之前的代码:

<?php
require "vendor/autoload.php";
use PHPHtmlParser\Dom;

$originEvernoteHtml = ‘<div><br />……’;

$dom = new Dom;

$dom->load($originEvernoteHtml);

$codeBlockHtml = $dom->find(‘div’)[0];

echo(“codeBlockHtml=”.$codeBlockHtml);

error_log($codeBlockHtml);

?>

即可。

去调试

Launch currently open script

打印出对应值了:

codeBlockHtml=<div><br /></div>

<div><br /></div>

转载请注明:在路上 » 【已解决】Mac中安装和使用composer安装php的库php-html-parser

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.218 seconds, using 22.09MB memory