PHPackages                             soliphp/helpers - 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. soliphp/helpers

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

soliphp/helpers
===============

Soli PHP helpers.

v1.1.0(7y ago)12802MITPHPPHP &gt;=5.5.0

Since Nov 10Pushed 7y ago1 watchersCompare

[ Source](https://github.com/soliphp/helpers)[ Packagist](https://packagist.org/packages/soliphp/helpers)[ Docs](https://github.com/soliphp/helpers)[ RSS](/packages/soliphp-helpers/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (5)DependenciesVersions (6)Used By (2)

Soli helpers
------------

[](#soli-helpers)

常用的 PHP「辅助」函数。

[![Build Status](https://camo.githubusercontent.com/45470e2d4d82a14fec900fee6eb9c9d9b77fcd24011bd3a83822fe3387bb82a8/68747470733a2f2f7472617669732d63692e6f72672f736f6c697068702f68656c706572732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/soliphp/helpers)[![Coverage Status](https://camo.githubusercontent.com/7beb4a364e8fc0309e7a1fa6d53eea1858e1bb023ab9663c834e6c4fba5f24f1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736f6c697068702f68656c706572732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/soliphp/helpers?branch=master)[![License](https://camo.githubusercontent.com/696cff42ab152007b13fd132532277a05a94c9a44f95d657359f7a901d9a450b/68747470733a2f2f706f7365722e707567782e6f72672f736f6c697068702f68656c706572732f6c6963656e7365)](https://packagist.org/packages/soliphp/helpers)

Table of Contents
=================

[](#table-of-contents)

- [字符串](#%E5%AD%97%E7%AC%A6%E4%B8%B2)
    - [camelize](#camelize)
    - [uncamelize](#uncamelize)
    - [lower](#lower)
    - [upper](#upper)
    - [starts\_with](#starts_with)
    - [ends\_with](#ends_with)
    - [contains](#contains)
    - [sanitize](#sanitize)
- [JSON](#json)
    - [is\_json](#is_json)
- [文件目录](#%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95)
    - [mkdir\_p](#mkdir_p)
- [环境变量](#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F)
    - [env](#env)
    - [env\_file](#env_file)

字符串
---

[](#字符串)

### camelize

[](#camelize)

`camelize` 函数将给定字符串转换为 `驼峰格式`：

```
echo camelize('coco_bongo'); // CocoBongo
echo camelize('co_co-bon_go', '-'); // Co_coBon_go
echo camelize('co_co-bon_go', '_-'); // CoCoBonGo

```

### uncamelize

[](#uncamelize)

`uncamelize` 函数将给定的字符串转换为 `蛇形格式`：

```
echo uncamelize('CocoBongo'); // coco_bongo
echo uncamelize('CocoBongo', '-'); // coco-bongo

```

### lower

[](#lower)

`lower` 函数将给定的字符串转换为 `小写`：

```
echo lower('HELLO'); // hello

```

### upper

[](#upper)

`upper` 函数将给定的字符串转换为 `大写`：

```
echo upper('hello'); // HELLO

```

### starts\_with

[](#starts_with)

`starts_with` 函数判断给定的字符串的`开头`是否是指定值：

```
echo starts_with('Hello', 'He'); // true
echo starts_with('Hello', 'he'); // false

```

### ends\_with

[](#ends_with)

`ends_with` 函数判断给定的字符串`结尾`是否是指定的内容：

```
echo ends_with('Hello', 'llo'); // true
echo ends_with('Hello', 'LLO'); // false

```

### contains

[](#contains)

`contains` 函数判断字符串是否`包含`指定的值：

```
echo contains('Hello', 'ell'); // true
echo contains('Hello', 'hll'); // false
echo contains('Hello', ['hll', 'ell']); // true
echo contains('Hello', ['hll', '']); // false

```

### sanitize

[](#sanitize)

`sanitize` 使用对应过滤标识进行数据清洗，如：

```
echo sanitize('!100a019.01a', 'int'); // 10001901
echo sanitize('{"data":123}', 'string'); // {&#34;data&#34;:123}
echo sanitize('some(one)@exa\\mple.com', 'email'); // someone@example.com

```

可用的过滤标识有：

标识描述int整数absint绝对值float小数alnum字母和数字alpha字母email邮箱urlURLtrim同 trim()string字符串strip\_tags同 strip\_tags()special将特殊字符转换为 HTML Entity Name：如 `
