ลบตัวอักษรพิเศษออกจากข้อความ

as usual , this topic begin from question "how to remove special string from our string.?" and i found this solution from "stackoverflow.com" so i write it down for reminder.

<?php
function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
   $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
   return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
?>

http://stackoverflow.com
http://www.unexpectedit.com

แสดงความคิดเห็น

0 ความคิดเห็น