PHPackages                             hejunjie/utils - 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. hejunjie/utils

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

hejunjie/utils
==============

一个零碎但实用的 PHP 工具函数集合库。包含文件、字符串、数组、网络请求等常用函数的工具类集合，提升开发效率，适用于日常 PHP 项目辅助功能 | A lightweight and practical PHP utility library that offers a collection of commonly used helper functions for files, strings, arrays, and HTTP requests—designed to streamline development and support everyday PHP projects.

v1.2.3(3mo ago)17.8k↓15.8%1MITPHPPHP &gt;=8.1

Since Apr 12Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/zxc7563598/php-utils)[ Packagist](https://packagist.org/packages/hejunjie/utils)[ RSS](/packages/hejunjie-utils/feed)WikiDiscussions main Synced yesterday

READMEChangelog (7)DependenciesVersions (11)Used By (1)

hejunjie/utils
==============

[](#hejunjieutils)

 [English](./README.md)｜[简体中文](./README.zh-CN.md)---

A lightweight and practical PHP utility library that offers a collection of commonly used helper functions for files, strings, arrays, and HTTP requests—designed to streamline development and support everyday PHP projects.

> 🌱 Many of these implementations are conceptually simple, but rewriting them repeatedly across projects can become quite tedious. To make things easier, I gathered these utilities in one place to avoid reinventing the wheel — saving both time and effort.

**This project has been parsed by Zread. If you need a quick overview of the project, you can click here to view it：[Understand this project](https://zread.ai/zxc7563598/php-utils)**

Installation
------------

[](#installation)

Install via Composer:

```
composer require hejunjie/utils
```

Purpose &amp; Motivation
------------------------

[](#purpose--motivation)

This is a typical "Developer's Time-Saving Toolkit." In everyday projects, you may often find yourself dealing with situations like:

Rewriting array operations over and over again;

- Searching StackOverflow every time you need to format file sizes;
- Copy-pasting checks to determine if a string is JSON, a phone number, or an email address;
- Having to refactor your utility classes whenever the project changes...

So, I’ve compiled these simple and frequently-used methods into this toolkit. It’s not about complexity or fancy features; the goal is to keep it simple, easy to use, and save you time and effort.

Currently Supported Methods (Updating)
--------------------------------------

[](#currently-supported-methods-updating)

List of Currently Supported Methods
-----------------------------------

[](#list-of-currently-supported-methods)

### String Operations

[](#string-operations)

methoddescribeStr::containsAny()Check if a string contains any of the elements in an arrayStr::padString()Pad a string to a specified length with a specific characterStr::replaceFirst()Replace the first occurrence of a search value in a stringStr::generateRandomString()Generate a random stringStr::getRandomSurname()Get a random surnameStr::truncateString()Truncate a stringStr::maskString()String maskingStr::removeWhitespace()Remove all whitespace characters from a stringStr::stringEncrypt()Encrypt a string (AES-128-CBC)Str::stringDecrypt()Decrypt a string (AES-128-CBC)Str::formatDurationFromSeconds()Convert seconds to a human-readable time format### Array Operations

[](#array-operations)

methoddescribeArr::arrayIntersect()Get the intersection of two arraysArr::sortByField()Sort a 2D array by a specific fieldArr::removeDuplicatesByField()Remove duplicates from a 2D array based on a specific fieldArr::groupByField()Group a 2D array by a specific fieldArr::csvToArray()Read a CSV file and return it as an arrayArr::arrayToCsv()Convert an array to a CSV formatted stringArr::xmlParse()Parse XML into an arrayArr::arrayToXml()Convert an array to XML### File Operations

[](#file-operations)

methoddescribeFileUtils::readFile()Read file contentsFileUtils::writeToFile()Write content to a fileFileUtils::getFileExtension()Get the file extensionFileUtils::joinPaths()Join multiple paths togetherFileUtils::getFileNameWithoutExtension()Get the file name (without extension)FileUtils::fileDelete()Delete a file or directoryFileUtils::writeUniqueLinesToFile()Get unique lines from a file (deduplication)FileUtils::getCommonLinesFromFiles()Get intersecting lines from multiple filesFileUtils::extractColumnFromCsvFiles()Quickly extract columns from multiple CSV files### CSV operation

[](#csv-operation)

MethodExplanationCsv::readCsvToArray()Read CSV file and convert to arrayCsv::arrayToCsv()Write the array to a CSV file### Network Request Operations

[](#network-request-operations)

methoddescribeHttpClient::sendGetRequest()Send a GET request using cURLHttpClient::sendPostRequest()Send a POST request using cURLHttpClient::downloadFile()Download remote files and save them locally### Image Operations

[](#image-operations)

methoddescribeImg::downloadImageFromUrl()Download an image from a URLImg::imageToBase64()Convert an image to a Base64 stringImg::base64ToImage()Save a Base64 string as an imageImg::compressImage()Compress an image to a specified size (in KB), with support for converting various formats to JPEGImg::resizeImage()Resize an image while maintaining aspect ratio### Export Operations

[](#export-operations)

methoddescribeDataExporter::exportTxt()Export TXTDataExporter::exportMarkdown()Export MarkdownDataExporter::exportCsv()Export CSVDataExporter::exportJson()Export JSONDataExporter::exportSql()Export SQLDataExporter::exportHtml()Export HTMLDataExporter::exportXml()Export XML🔧 Additional Toolkits (Can be used independently or installed together)
-----------------------------------------------------------------------

[](#-additional-toolkits-can-be-used-independently-or-installed-together)

This project was originally extracted from [hejunjie/tools](https://github.com/zxc7563598/php-tools). To install all features in one go, feel free to use the all-in-one package:

```
composer require hejunjie/tools
```

Alternatively, feel free to install only the modules you need：

[hejunjie/utils](https://github.com/zxc7563598/php-utils) - A lightweight and practical PHP utility library that offers a collection of commonly used helper functions for files, strings, arrays, and HTTP requests—designed to streamline development and support everyday PHP projects.

[hejunjie/cache](https://github.com/zxc7563598/php-cache) - A layered caching system built with the decorator pattern. Supports combining memory, file, local, and remote caches to improve hit rates and simplify cache logic.

[hejunjie/china-division](https://github.com/zxc7563598/php-china-division) - Regularly updated dataset of China's administrative divisions with ID-card address parsing. Distributed via Composer and versioned for use in forms, validation, and address-related features

[hejunjie/error-log](https://github.com/zxc7563598/php-error-log) - An error logging component using the Chain of Responsibility pattern. Supports multiple output channels like local files, remote APIs, and console logs—ideal for flexible and scalable logging strategies.

[hejunjie/mobile-locator](https://github.com/zxc7563598/php-mobile-locator) - A mobile number lookup library based on Chinese carrier rules. Identifies carriers and regions, suitable for registration checks, user profiling, and data archiving.

[hejunjie/address-parser](https://github.com/zxc7563598/php-address-parser) - An intelligent address parser that extracts name, phone number, ID number, region, and detailed address from unstructured text—perfect for e-commerce, logistics, and CRM systems.

[hejunjie/url-signer](https://github.com/zxc7563598/php-url-signer) - A PHP library for generating URLs with encryption and signature protection—useful for secure resource access and tamper-proof links.

[hejunjie/google-authenticator](https://github.com/zxc7563598/php-google-authenticator) - A PHP library for generating and verifying Time-Based One-Time Passwords (TOTP). Compatible with Google Authenticator and similar apps, with features like secret generation, QR code creation, and OTP verification.

[hejunjie/simple-rule-engine](https://github.com/zxc7563598/php-simple-rule-engine) - A lightweight and flexible PHP rule engine supporting complex conditions and dynamic rule execution—ideal for business logic evaluation and data validation.

👀 All packages follow the principles of being lightweight and practical — designed to save you time and effort. They can be used individually or combined flexibly. Feel free to ⭐ star the project or open an issue anytime!

---

This library will continue to be updated with more practical features. Suggestions and feedback are always welcome — I’ll prioritize new functionality based on community input to help improve development efficiency together.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance78

Regular maintenance activity

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~36 days

Recently: every ~72 days

Total

10

Last Release

115d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b65d4b40ae456172fb38f63f84bf737ac88031484b1f228b1cc8d71baa80adf?d=identicon)[苏青安](/maintainers/%E8%8B%8F%E9%9D%92%E5%AE%89)

---

Top Contributors

[![zxc7563598](https://avatars.githubusercontent.com/u/46590942?v=4)](https://github.com/zxc7563598 "zxc7563598 (25 commits)")

---

Tags

array-utilscomposerfile-utilshelper-functionsnetwork-utilsphpphp8string-utilsutils

### Embed Badge

![Health badge](/badges/hejunjie-utils/health.svg)

```
[![Health](https://phpackages.com/badges/hejunjie-utils/health.svg)](https://phpackages.com/packages/hejunjie-utils)
```

PHPackages © 2026

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