定制 fabgg/url-search-params 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fabgg/url-search-params

最新稳定版本:1.1

Composer 安装命令:

composer require fabgg/url-search-params

包简介

Library implement UrlSearchParams inspired of eponym class in Javascript

README 文档

README

This is a php library inspired by JavaScript's URLSearchParams class.

Installation

This can also be installed with composer.

$ composer require fabgg/url-search-params

This library follows the PSR-4 convention names for its classes, which means you can easily integrate url-search-params classes loading in your own autoloader.

Getting Started

Basic example of how to use this library

<?php

// Include dependencies installed with composer
require 'vendor/autoload.php';

use Fabgg\UrlSearchParams\URLSearchParams;

$search = new URLSearchParams('?q=github');
$search->merge(['user'=>'fabrice'])
echo $search->toString();

The result would render the following string : ?q=github&user=fabrice

Usage

Use URLSearchParams directly. You can instantiate a new instance of URLSearchParams from a string or an array.

<?php
$search = new URLSearchParams('?q=github+web+site&u=yan');
// equivalent to:
$search = new URLSearchParams(['q' => 'github web site', 'u' => 'yan']);

append

$search= new URLSearchParams();
// array
search->append(["id"=> 1]);

appendTo

$search = new URLSearchParams();
// key and value
$search->appendTp("id"=> 1);
// value can be an array
$search->appendTp("id"=> [3,5,7]);
echo (string)$search;
// result is `?id=1&id=3&id=5&id=7`

delete

$search.delete("id");

get

$search.get("id");
// return an array [1, 3, 5, 7]

getAll

$search = new URLSearchParams('?q=github&u=yan');
// all query parameters are
$search.getAll();
// return ['q' => ['github'], 'u' => ['yan']]
$search.getAll("q");
// return ['q' => ['github']] like $search->get('q')

has

$search.has("id");

merge

$search = new URLSearchParams('?q=vegetable&flavour=sweet');
$search->merge('?q=fruits');
echo $search->toString();
// return '?q=vegetable&q=fruits&flavour=sweet'
$search->merge(['flavour' => 'bitter','color'=>'red tomato']);
echo $search->toString();
// return '?q=vegetable&q=fruits&flavour=sweet&flavour=bitter&color=red+tomato'

toString

$search.toString();
// or call __toString()
(string)$search;

keys

$search = new URLSearchParams('?q=github&u=yan');
$search->keys();
// return ['q','u']

LICENSE

MIT license

统计信息

  • 总下载量: 269
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固