tzfrs/urlpruner

该库接收一个URL,并从其中删除(可能)不必要的数据

1.2 2016-01-08 13:57 UTC

This package is not auto-updated.

Last update: 2024-09-25 23:19:07 UTC


README

一个易于使用的URL修剪库

安装

通过 composer 安装

composer require tzfrs\urlpruner

运行 composer installcomposer update

方法

anythingAfter - 从URL中删除字符/单词之后的所有内容

regex - 根据正则表达式删除URL的一部分

parameters - 删除具有特定键的参数

allParameters - 删除所有参数

parameterValues - 删除具有特定值的键的所有参数

prune - 实际执行修剪操作

入门指南

基本修剪

<?php
require __DIR__ . '/vendor/autoload.php';

$url = 'https://www.google.de/search?num=30&site=&source=hp&q=software+development&oq=Software+Development&gs_l=hp.3.0.0l10.464.4794.0.5387.31.18.3.7.8.0.185.1953.1j14.15.0....0...1c.1.64.hp..8.23.1779.0._BnKQF4413M';

$urlPruner = new \tzfrs\URLPruner\URLPruner();

print $urlPruner->anythingAfter('search')
    ->prune($url); // https://www.google.de/search

print $urlPruner->regex('search')
    ->prune($url); // https://www.google.de/?num=30&site=&source=hp&q=software+development&oq=Software+Development&gs_l=hp.3.0.0l10.464.4794.0.5387.31.18.3.7.8.0.185.1953.1j14.15.0....0...1c.1.64.hp..8.23.1779.0._BnKQF4413M

print $urlPruner->parameters(['num', 'q'])
    ->prune($url); // https://www.google.de/search?site=&source=hp&oq=Software+Development&gs_l=hp.3.0.0l10.464.4794.0.5387.31.18.3.7.8.0.185.1953.1j14.15.0....0...1c.1.64.hp..8.23.1779.0._BnKQF4413M

print $urlPruner->allParameters()
    ->prune($url); // https://www.google.de/search

print $urlPruner->parameterValues(['30', '', 'hp'])
    ->prune($url); // https://www.google.de/search?q=software+development&oq=Software+Development&gs_l=hp.3.0.0l10.464.4794.0.5387.31.18.3.7.8.0.185.1953.1j14.15.0....0...1c.1.64.hp..8.23.1779.0._BnKQF4413M

贡献当然是被允许的!:-)

有关许可信息,请参阅文件 LICENSE