Skip to content

Commit

Permalink
Permlink content with number. overtrue#54
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed May 21, 2016
1 parent 22fafbd commit f9e9256
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use Overtrue\Pinyin\Pinyin;
$pinyin = new Pinyin();

$pinyin->convert('带着希望去旅行,比到达终点更美好');
// ["dai", "zhe", "xi", "wang", "qu", "lu", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]

$pinyin->convert('带着希望去旅行,比到达终点更美好', PINYIN_UNICODE);
// ["dài","zhe","xī","wàng","qù","lǚ","xíng","bǐ","dào","dá","zhōng","diǎn","gèng","měi","hǎo"]
Expand All @@ -47,8 +47,8 @@ $pinyin->convert('带着希望去旅行,比到达终点更美好', PINYIN_ASCI
### 生成用于链接的拼音字符串

```php
$pinyin->permlink('带着希望去旅行'); // dai-zhe-xi-wang-qu-lu-xing
$pinyin->permlink('带着希望去旅行', '.'); // dai.zhe.xi.wang.qu.lu.xing
$pinyin->permlink('带着希望去旅行'); // dai-zhe-xi-wang-qu-lv-xing
$pinyin->permlink('带着希望去旅行', '.'); // dai.zhe.xi.wang.qu.lv.xing
```

### 获取首字符字符串
Expand Down
2 changes: 1 addition & 1 deletion src/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected function convertSurname($string, $dictLoader) {
*/
public function splitWords($pinyin, $option)
{
$split = array_filter(preg_split('/[^üāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜa-z]+/iu', $pinyin));
$split = array_filter(preg_split('/[^üāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜa-z\d]+/iu', $pinyin));

if ($option !== self::UNICODE) {
foreach ($split as $index => $pinyin) {
Expand Down
3 changes: 3 additions & 0 deletions tests/PinyinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function testPermlink()
$this->assertSame('dai.zhe.xi.wang.qu.lv.xing', $pinyin->permlink('带着希望去旅行', '.'));
$this->assertSame('daizhexiwangqulvxing', $pinyin->permlink('带着希望去旅行', ''));

// with number.
$this->assertSame('1-dai-23-zhe-5-6-xi-wang-qu-abc-lv-xing-568', $pinyin->permlink('1带23着。!5_6.=希望去abc旅行568'));

$this->setExpectedException('InvalidArgumentException', "Delimiter must be one of: '_', '-', '', '.'.");

$this->assertSame('daizhexiwangqulvxing', $pinyin->permlink('带着希望去旅行', '='));
Expand Down

0 comments on commit f9e9256

Please sign in to comment.