Skip to content

Commit 7fd2bc8

Browse files
committed
Initail commit
1 parent 8514beb commit 7fd2bc8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

text_to_slug.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
class StrTextSlug {
3+
4+
function stringToSlug( $str , $maxLength = 1000 , $rc = '-'){
5+
6+
$str = strtolower(trim($str));
7+
$str = preg_replace('/-+/', $rc , $str);
8+
$str = preg_replace("/[\s-]+/", $rc , $str);
9+
$str = preg_replace("/\s/", "-", $str);
10+
$special_chars = array("?","%", "." , "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}","+");
11+
$str = str_replace($special_chars, '', $str);
12+
13+
$str = trim(preg_replace("/[\/_|+ -]+/", $rc, $str));
14+
$str = trim(substr($str, 0, $maxLength));
15+
16+
return $str;
17+
18+
}
19+
20+
}
21+

0 commit comments

Comments
 (0)