หัวข้อ: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขียน script แบบไหนครับ เริ่มหัวข้อโดย: asunza ที่ 05 มิถุนายน 2010, 15:23:48 ผมต้องการตัดเครื่องหมายพวกนี้ออก + / * ! ( ) & % $ # @ > < ?
เขียน script PHP แบบไหนครับ เช่น word-word+word*word/word%word$word#word ให้เป็นแบบนี้ word-word-word-word-word-word-word-word :wanwan017: หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขี& เริ่มหัวข้อโดย: kongpair ที่ 05 มิถุนายน 2010, 15:47:39 <?php
$oldstring = 'some+thing about us "super" demo'; $string_to_replace = array ("+" , "/" , "*" , "!" , "(" , ")" , "&" , "%" , "$" , "#" , "@" , ">" , "<" , "?" , " "); $string_after_replace = array ("-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-"); $newstring = str_replace($string_to_replace , $string_after_replace , $oldstring , $count); echo $newstring; ?> RESULT : some-thing-about-us-super-demo หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขียน script แบบไหนครับ เริ่มหัวข้อโดย: asunza ที่ 05 มิถุนายน 2010, 15:58:59 ขอบคุณมากครับ :wanwan017:
หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขี& เริ่มหัวข้อโดย: xvlnw.com ที่ 04 ตุลาคม 2011, 15:26:30 function rewrite_url($url="url"){
$url = strtolower(preg_replace('~[^a-z0-9ก-๙\.\-\_]~iu','-',$url)); return $url ; } $oldstring = 'some+thing about us "super" demo'; echo rewrite_url($oldstring); หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขียน script แบบไหนครับ เริ่มหัวข้อโดย: seowizard ที่ 04 ตุลาคม 2011, 17:01:12 ใช้ regular expression เอาครับ ง่ายดี
$str_reg = "word-word+word*word/word%word$word#word"; echo preg_replace("/[\*|!|\(|\)|&|%|\$|#|@|<|>|\?|\+|\/]/", "-", $str_reg); หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขี& เริ่มหัวข้อโดย: WPDSign ที่ 04 ตุลาคม 2011, 17:31:43 <?php $oldstring = 'some+thing about us "super" demo'; $string_to_replace = array ("+" , "/" , "*" , "!" , "(" , ")" , "&" , "%" , "$" , "#" , "@" , ">" , "<" , "?" , " "); $string_after_replace = array ("-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-"); $newstring = str_replace($string_to_replace , $string_after_replace , $oldstring , $count); echo $newstring; ?> RESULT : some-thing-about-us-super-demo ผมใช้ตามนี้เลยครับ พอดีเคยตั้งกระทู้ถาม เหมือนกัน หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขี& เริ่มหัวข้อโดย: Synchronize ที่ 04 ตุลาคม 2011, 19:16:50 <?php $oldstring = 'some+thing about us "super" demo'; $string_to_replace = array ("+" , "/" , "*" , "!" , "(" , ")" , "&" , "%" , "$" , "#" , "@" , ">" , "<" , "?" , " "); $string_after_replace = array ("-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-" , "-"); $newstring = str_replace($string_to_replace , $string_after_replace , $oldstring , $count); echo $newstring; ?> RESULT : some-thing-about-us-super-demo ตัวแปล $count มาจากไหนเหรอครับ :wanwan017: หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขียน script แบบไหนครับ เริ่มหัวข้อโดย: engiblog.com ที่ 04 ตุลาคม 2011, 21:55:22 ลองใช้ regular expression ไหมครับ เช่น ต้องการแต่ตัวอักษรภาษาอังกฤษและตัวเลข
$ผลลัพท์ที่ได้ = preg_replace('/[^a-zA-Z0-9-]/s', '', $ที่ต้องการตัด); หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขียน script แบบไหนครับ เริ่มหัวข้อโดย: kritsanatt ที่ 04 ตุลาคม 2011, 22:35:38 โอวเทพโปรแกรมเมอร์ ต้องใช้ function นี้เหมือนกัน มาขอเก็บไปก่อนละครับ ขอบคุณครับ :'(
หัวข้อ: Re: ต้องการตัดเครื่องหมายออก เช่น + / * ! ( ) &%$#@><? เขียน script แบบไหนครับ เริ่มหัวข้อโดย: starpic ที่ 11 ตุลาคม 2011, 23:11:55 เอาไปใช้ยังไงเหรอครับ
|