Skip to content

Commit 38d4838

Browse files
committed
Update HTMLHelper.php
1 parent a3ef94c commit 38d4838

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

berry/utils/HTMLHelper.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,17 @@ public function GetHTMLTags(string $tag, string $html): array
3434
*/
3535
public function URLFriendly(string $string): string
3636
{
37-
$string = str_replace('.', "", $string);
38-
$string = str_replace('!', "", $string);
39-
$string = str_replace('(', "", $string);
40-
$string = str_replace(')', "", $string);
41-
$string = str_replace(" ", "-", $string);
42-
$string = str_replace("\\", "", $string);
43-
$string = str_replace("/", "", $string);
44-
$string = str_replace('"', "", $string);
37+
// Remove unwanted characters
38+
$string = strtolower($string);
39+
$unwantedChars = ['.', '!', '(', ')', '\\', '/', '"', ' '];
40+
$string = str_replace($unwantedChars, ['', '', '', '', '', '', '', '-'], $string);
4541
$string = preg_replace("`\[.*\]`U", "", $string);
4642
$string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '-', $string);
4743
$string = preg_replace("`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i", "\\1", $string);
48-
return strtolower(trim($string, '-'));
44+
$string = preg_replace('~[^a-z0-9\-]+~', '', $string);
45+
$string = preg_replace('~-+~', '-', $string);
46+
return trim($string, '-');
4947
}
50-
5148
}
5249

5350
?>

0 commit comments

Comments
 (0)