PHPackages                             nyholm/append-query-string - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nyholm/append-query-string

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nyholm/append-query-string
==========================

A simple function that lets you add a query string to an existing URL

1.0.0(4y ago)20290.6k↑24.5%2[1 PRs](https://github.com/Nyholm/append_query_string/pulls)2MITPHPPHP ^7.2 || ^8.0CI failing

Since Jan 28Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/Nyholm/append_query_string)[ Packagist](https://packagist.org/packages/nyholm/append-query-string)[ GitHub Sponsors](https://github.com/nyholm)[ RSS](/packages/nyholm-append-query-string/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (2)

PHP function to append query string to URL.
===========================================

[](#php-function-to-append-query-string-to-url)

If you have a unknown URL and want to add a query string to it, this package is what you are looking for.

Install
-------

[](#install)

```
composer require nyholm/append-query-string

```

Usage
-----

[](#usage)

```
$url = 'https://nyholm.tech?example=yes';
$queryString = http_build_query(['foo'=>'bar']);

$result = append_query_string($url, $queryString);

echo $result;
// https://nyholm.tech?example=yes&foo=bar
```

Yes, this is pretty much as writing:

```
$result = $url . $queryString;
```

But it will support if URL has query string or not. It will also if a URL hash fragment is used.

Modes
-----

[](#modes)

There are three different modes you can use with `append_query_string`.

- `APPEND_QUERY_STRING_IGNORE_DUPLICATE` (default)
- `APPEND_QUERY_STRING_REPLACE_DUPLICATE`
- `APPEND_QUERY_STRING_SKIP_DUPLICATE`

They are easiest explained with examples.

#### APPEND\_QUERY\_STRING\_IGNORE\_DUPLICATE

[](#append_query_string_ignore_duplicate)

```
$url = 'https://nyholm.tech?foo=x&a=1';
$queryString = http_build_query(['a'=>'2']);

$result = append_query_string($url, $queryString, APPEND_QUERY_STRING_IGNORE_DUPLICATE);

echo $result;
// https://nyholm.tech?foo=x&a=1&a=2
```

#### APPEND\_QUERY\_STRING\_REPLACE\_DUPLICATE

[](#append_query_string_replace_duplicate)

```
$url = 'https://nyholm.tech?foo=x&a=1';
$queryString = http_build_query(['a'=>'2']);

$result = append_query_string($url, $queryString, APPEND_QUERY_STRING_REPLACE_DUPLICATE);

echo $result;
// https://nyholm.tech?foo=x&a=2
```

#### APPEND\_QUERY\_STRING\_SKIP\_DUPLICATE

[](#append_query_string_skip_duplicate)

```
$url = 'https://nyholm.tech?foo=x&a=1';
$queryString = http_build_query(['a'=>'2']);

$result = append_query_string($url, $queryString, APPEND_QUERY_STRING_SKIP_DUPLICATE);

echo $result;
// https://nyholm.tech?foo=x&a=1
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance56

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 86.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~282 days

Total

3

Last Release

1817d ago

Major Versions

0.1.1 → 1.0.02021-08-16

PHP version history (2 changes)0.1.0PHP ^7.2

1.0.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/401ccc5eea13c60cf807ae982af00e368e2166e2f26d8eb541dcd881a57385bc?d=identicon)[Nyholm](/maintainers/Nyholm)

---

Top Contributors

[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (13 commits)")[![carlos-ea](https://avatars.githubusercontent.com/u/5512089?v=4)](https://github.com/carlos-ea "carlos-ea (1 commits)")[![NikoGrano](https://avatars.githubusercontent.com/u/4658966?v=4)](https://github.com/NikoGrano "NikoGrano (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nyholm-append-query-string/health.svg)

```
[![Health](https://phpackages.com/badges/nyholm-append-query-string/health.svg)](https://phpackages.com/packages/nyholm-append-query-string)
```

###  Alternatives

[dillingham/soft-deletes-parent

Soft delete children when parent soft deletes

561.3k](/packages/dillingham-soft-deletes-parent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
