 |
|
สอบถามเรื่องฟั่งชั่นอะค่ะ
สมมติรับค่ามาเป็น tel: 0810101001 www.tezs.com 152/9 อ.เมือง
คือจะเปลี่ยนจาก www.tezs.comเปน www.xxx.com
และจะเปลี่ยน จากเบอร์โทรเปน 0810101001 เป็น 0xxxxxxx
แต่ตอนนี้มันเปลี่ยนได้แต่ เบอร์โทรศัพท์อย่างเดียวอะค่ะ
Code (PHP)
function url2x($temp){
$protocol =array("/(http:\/\/)/","/(https:\/\/)/","/(ftp:\/\/)/");
$replace =array("xxxx://","xxxxx://","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)
echo $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;
}
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2011-06-01 12:12:53 |
By :
kwangz_07 |
View :
891 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |