สอบถามวิธีการ เปลี่ยนข้อความที่รับมาจาก texteditor ของ ckeditor

สอบถามวิธีการ เปลี่ยนข้อความที่รับมาจาก texteditor ของ ckeditor



สมมติรับค่ามาเป็น tel: 0810101001 www.tezs.com 152/9 อ.เมือง



คือจะเปลี่ยนจาก www.tezs.comเปน www.xxx.xxx



และจะเปลี่ยน จากเบอร์โทรเปน 0810101001 เป็น 0xxxxxxx



แต่ตอนนี้มันเปลี่ยนได้แต่ เบอร์โทรศัพท์อย่างเดียวอะค่ะ
ไม่รู้ต้องทำไงต่ออะค่ะ



$temp=$p_detail;

                

echo url2x($temp);



function url2x($temp){

      $protocol =array("/(http:\/\/)/","/(https:\/\/)/","/(ftp:\/\/)/","/(www.\/\/)/");

    $replace =array("xxxx://","xxxxx://","xxx://","xxx.//");

    $temp = preg_replace($protocol,$replace,$temp); // เปลี่ยนโปรโตคอลให้เป็น xx://

    

    $posURL=0;  

    $posNextURL =strpos($temp,"xxx://",$posURL)+strlen("xxx://");

    while($posURL<$posNextURL){   // วนลูปหา url ตัวอื่น

        $posURL=$posNextURL ;

        $posEndURL= strpos($temp,' ',$posURL);

        if($posURL>$posEndURL) $posEndURL=strlen($temp);

        $URLlen=$posEndURL-$posURL;

        $url =substr($temp,$posURL,$URLlen);

        $replace =preg_replace("/[^\.\/<>]/","x",$url);

        $temp = preg_replace("($url)",$replace,$temp); //เปลี่ยน url  นี้ให้เป็น xx

        $parentURL=preg_replace('/([\w]+)\/(.*)/','\\1',$url);

        $replace =preg_replace("/[^\.\/<>]/","x",$parentURL);

        $temp = preg_replace("($parentURL)",$replace,$temp);

        $posNextURL=strpos($temp,"xxx://",$posURL)+strlen("xxx://");  

        $posURL =$posEndURL+1;

    }

    return  $temp;

}




ช่วยด้วยค่ะ
01 มิ.ย. 2554 7 2,121

ถ้าต้องการให้เป็นแค่ www.xxx.xxx ก็ไม่ใส่ค่าไปเ้ลยละครับ ทำไมต้องไปแปรงหรือว่าทำอะไรกับค่าที่ได้

ในเมื่อผลที่ต้องการออกมาให้เป็นแค่ www.xxx.xxx ค่าคงตัวอยู่แล้วนิครับ



ไม่ทราบว่าผมเข้าใจถูกในคำถามหรือปล่าว



#1

คือเค้าอยากให้แปรงค่าไว่เวลาไปโชว์
#2

คือจะกันไม่เข้าใส่ลิ้งไปยังเว็บนั้นนอะค่ะ
#3

ก็หน้าโชว์ก็ใส่ที่จะโชว์ไปเป็น www.xxx.com ได้เลยนิครับ ก็ไม่จำเป็นต้องแปรงให้เมื่อยเลยนินา อิอิ 



เพราะว่าจะแปลงหรือไม่แปลงก็คลิกไปลิงค์นั้นไม่ได้อยู่ดีถูกต้องหรือปล่าวครับ 
#4

ก็ดัดแปลงเอาจาก BBCode ที่นิยมใช้กันสำหรับการแปลงข้อความเป็นลิงค์ก็ได้นี่ครับ



$patt[] = '/((^http|\shttp):\/\/([^\s<>\"\']+))/';

$replace[] = 'http://xxx.xxx';
#5

function BBCodeFormat($str, $removeTags = FALSE){

    $pattern=array('/((^http|\shttp):\/\/([^\s<>\"\']+))/');

    $replace=array('http://xxx.xxx');

    // Replace Tags

    $str = preg_replace($pattern, $replace, $str);

    // Replace Quotes

    $open = '<blockquote>';

    $close = '</blockquote>';

    preg_match_all ('/\[quote\]/i', $str, $matches);

    $opentags = count($matches['0']);

    preg_match_all ('/\[\/quote\]/i', $str, $matches);

    $closetags = count($matches['0']);

    $unclosed = $opentags - $closetags;

    for ($i = 0; $i < $unclosed; $i++)$str .= '</blockquote>';

    $str = str_replace ('



', $open, $str);

    $str = str_replace ('[/' . 'quote]', $close, $str);

    return $str;

}



     $str=$str;

     echo BBCodeFormat($str);





ไม่แน่ใจว่าทำแบบนี้จะถูกรึป่าวอะค่ะ



แต่พอ echo ออกมา มันก่ไม่เปลี่ยนอะค่ะ

 
#6

<?php

  $patt[] = '/((^http|\shttp):\/\/([^\s<>\"\']+))/';

  $replace[] = 'http://xxx.xxx';

  echo preg_replace($patt,$replace,'ทดสอบ http://www.goragod.com นะครับ');

?>



ผมให้แค่แนวคิดนะว่ามันทำแบบนี้ เนื่องจากไม่เคยทำแบบนี้ อาจต้องปรับปรุงเล็กน้อยเพื่อให้ใช้งานได้จริง สิ่งที่สำคัญคือลองค้นคว้าเพิ่มเติมเพื่อให้ได้สิ่งที่ต้องการ ตัวอย่างที่ต้องการสามารถหาได้มากมายบนเว็บครับ.



หรือไม่ก็รองคนที่เคยทำในแบบที่ตรงความต้องการเป๊ะๆมาตอบ (ว่าแต่จะมีหรือเปล่า)

#7
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^