ฟังก์ชั่นตัดคำหยาบ 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","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 = 'xxxจะฆ่าxxx';
  echo CheckRude( $txt ); // xxxจะฆ่าxxx
?>

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

เรื่องที่เกี่ยวข้อง

^