承接 janmensik/phphelpers 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

janmensik/phphelpers

最新稳定版本:v1.0.1

Composer 安装命令:

composer require janmensik/phphelpers

包简介

Pack of small helper functions for transformations input and outputs.

README 文档

README

PHPHelpers is a lightweight PHP library that provides a collection of utility functions to simplify common tasks such as string manipulation, data parsing, URL handling, and file system operations. It is designed to be easy to integrate and use in any PHP project.

Installation

Install the library via Composer:

composer require janmensik/phphelpers

Usage

Helpers Class

The Helpers class contains a variety of static methods for common tasks.

String Manipulation

utf2ascii(string $string): string

Converts a UTF-8 encoded string to its ASCII equivalent, removing diacritics. This is particularly useful for handling Latin-1 and Czech characters.

use JanMensik\PHPHelpers\Helpers;

$asciiString = Helpers::utf2ascii('Příliš žluťoučký kůň');
// echo $asciiString; // "Prilis zlutoucky kun"

text2seolink(string $string): string

Transforms a string into a URL-friendly "slug" by converting it to lowercase, replacing non-alphanumeric characters with hyphens, and trimming any leading or trailing hyphens.

use JanMensik\PHPHelpers\Helpers;

$seoLink = Helpers::text2seolink('A sample title with various characters!');
// echo $seoLink; // "a-sample-title-with-various-characters"

Data Parsing

parseFloat(?string $str): ?float

Parses a floating-point number from a string, correctly handling commas as decimal separators and ignoring whitespace.

use JanMensik\PHPHelpers\Helpers;

$floatValue = Helpers::parseFloat('1 234,56');
// var_dump($floatValue); // float(1234.56)

parseDate(?string $data, bool $force = false): ?int

Parses a date string into a Unix timestamp. It supports various date formats and defaults to noon if no time is specified.

use JanMensik\PHPHelpers\Helpers;

$timestamp = Helpers::parseDate('15. 12. 2023 14:30');
// echo $timestamp; // A Unix timestamp corresponding to the given date and time

UrlParameters Class

The UrlParameters class provides a simple and effective way to manipulate and construct URLs with query parameters.

Creating a URL

You can create a new URL instance from a string or from the current request URI.

use JanMensik\PHPHelpers\UrlParameters;

// From a string
$url = new UrlParameters('https://example.com/path?param1=value1');

// From the current request
$currentUrl = new UrlParameters();
$currentUrl->fromCurrent();

Modifying Parameters

You can easily add, update, or remove query parameters.

$url->setParameter('param2', 'newValue'); // Adds or updates a parameter
$url->setParameter('param1', false); // Removes a parameter

Generating Output

Once you have configured the URL, you can retrieve it as a string or as a complete HTML link.

$urlString = $url->getUrl();
// echo $urlString; // "https://example.com/path?param2=newValue"

$htmlLink = $url->getLink('Click Here', 'class="btn"');
// echo $htmlLink; // '<a href="https://example.com/path?param2=newValue" class="btn">Click Here</a>'

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-13