ฟังก์ชั่นตัดคำหยาบ PHP

ฟังก์ชั่นตัดคำหยาบซึ่งสามารถเพิ่มคำที่ต้องการตัดได้ โดยนำไปใส่ใน array $wordrude

function CheckRude( $temp )
{
     $wordrude = array( "xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","มึง","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","กู","ควย","xxx","xxx","xxx","xxx","ปี้","เหี้ย","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","สัด","เย็ด","หี","xxx","แม่ง","xxx","xxx","แตด" ) ; //คำหยาบ
     $wordchange = "<font class=\"red\">xxx</font>"; //ข้อความที่ต้องการให้เปลี่ยนเป็น

     for ( $i = 0 ; $i < sizeof( $wordrude ) ; $i++ )
     {
          $temp = eregi_replace ( $wordrude[$i] , $wordchange , $temp );
     };
    
     return $temp;
 }


การใช้งาน

<?
  $txt = 'กูจะฆ่ามึง';
  echo CheckRude( $txt ); // xxxจะฆ่าxxx
?>

ผู้เขียน goragod โพสต์เมื่อ 01 เม.ย. 2551 เปิดดู 13,057 ป้ายกำกับ PHP
^