olakunlevpn/php-helpers

PHP Helpers 是一个灵活且全面的 PHP 工具函数集合,旨在简化您的 PHP 开发流程。无论您是在构建 Web 应用程序、API 还是进行其他 PHP 项目,我们的包提供了一套广泛的工具,以简化常见任务并提高开发效率。

1.0.0 2023-10-08 15:09 UTC

This package is auto-updated.

Last update: 2024-09-08 17:16:21 UTC


README

License

php-helpers 是一个 PHP 工具库,提供了一系列有用的函数,用于简化 PHP 开发中的常见任务。

特性

  • JSON 处理:使用 json_message 函数轻松生成 JSON 响应。
  • 重定向:使用 redirect_to 函数管理重定向,即使头信息已经发送。
  • URL 操作:获取当前 URL,检查 AJAX 请求,并轻松处理 URL。
  • Gravatar 集成:为用户头像生成 Gravatar URL。
  • 安全:处理 CSRF 令牌和输入数据清理。
  • 数组操作:使用点表示法使用 array_setarray_forgetarray_get 操作数组。
  • 字符串操作:执行各种字符串操作,如大小写转换和子字符串检查。
  • 还有更多...

安装

您可以使用 Composer 轻松安装 php-helpers。在您的项目目录中运行以下命令

composer require olakunlevpn/php-helpers

安装后,您可以在需要其功能的 PHP 脚本中包含 Util 类。

require_once('vendor/autoload.php');

use Olakunlevpn\PhpHelpers\Util;

// Now you can use Util:: functions

使用方法

以下是一些使用 php-helpers 提供的函数的示例。

// Generate a JSON response
Util::json_message("Operation completed successfully", true);

// Redirect to a specific URL
Util::redirect_to("/home");

// Get the current URL
$currentUrl = Util::get_current_url();

// Check if it's an AJAX request
$isAjax = Util::is_ajax_request();

// Generate a Gravatar URL
$gravatarUrl = Util::gravatar("user@example.com", 120, 'identicon', 'pg');


// Generate a avatar with first name and last name
$avatarUrl = Util::avatar("John Timothy");



// Sanitize a string key
$sanitizedKey = Util::sanitize_key("user@123");

// Perform string operations
$studlyString = Util::studly_case("hello_world");

有关更多详细信息和使用示例,请参阅 文档

许可证

该项目是开源的,可在 MIT 许可证 下使用。

请随时贡献、报告问题或提出改进建议。您的反馈非常有价值!

使用 php-helpers 享受愉快的编码吧!

此更新的 README 提供了关于用户如何使用 Composer 安装 php-helpers 的明确说明。用户只需在项目目录中运行 composer require 命令即可包含库,然后可以在使用示例中所示的 PHP 脚本中使用它。