จะตัดคำข้างหน้าออกโดยใช้ php ยังไงครับ

เริ่มโดย hoke46, 24 ตุลาคม 2015, 19:46:26

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

hoke46

คือผมไม่ค่อยรู้เรื่อง php เท่าไรครับอยากทราบว่าเราจะเขียน php ให้มันตัดประโยคข้างหน้าออกยังไงครับ
เช่นคำว่า name@domain.com ให้มันตัดข้อความที่อยู่หน้าเครื่องหมาย @ ออกเหลือแต่คำว่า domain.com
คือผมลองเซิสหาวิธีใน google แล้วไม่เจอไม่รู้ว่าต้องใช้ keyword ไหนในการเซิส

BeerSkz

#1
$x = expode("@","[email protected]");
echo $x[1];

http://php.net/manual/en/function.explode.php

แต่ต้องระวัง input ซึ่งบางทีอาจมีแค่ @xx.xx หรือ xx@

smapan

<?php
function getDomainFromEmail($email)
{
    
$patrn "/@.+?(\..+)/";
    
preg_match($patrn$email$matches);
    return 
$matches[1];
}
 
// Example
 
$email "[email protected]";
 
$domain getDomainFromEmail($email);
 
echo 
$domain// yahoo.com
?>


from http://www.bitrepository.com/how-to-extract-domain-name-from-an-e-mail-address-string.html
[direct=http://cp.siamhostweb.com/cart.php?gid=1]จูมล่าโฮส สยามโฮสเว็บ[/direct] [direct=http://www.modty.com]modty.com[/direct]
[direct=http://www.apartment.in.th]รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง[/direct]
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***

coolsweet

[direct=http://www.daisukimag.com]รีวิวเกม[/direct]
[direct=http://www.daisukimag.com]รีวิวภาพยนตร์[/direct]
[direct=http://www.daisukimag.com]รีวิวอนิเมะ[/direct]
[direct=http://www.daisukimag.com/game/]Game[/direct]
[direct=http://www.daisukimag.com/game/]yokai saga[/direct]

A-LAND

ถ้าผมจะใช้ประมาณนี้ครับ สั้นๆ ง่ายๆ แต่ก็ใช้ได้แน่นอน

<?php
$email1 
'[email protected]';
$email2 $email1.'x';
preg_match('|@(.*?)x|'$email2$match);
echo 
$match[1];
?>


ถ้ารับค่ามาจาก POST ก็

<?php
$email1 
$_POST['email'];
$email2 $email1.'x';
preg_match('|@(.*?)x|'$email2$match);
echo 
$match[1];
?>


ถ้ารับค่าจากจาก GET

<?php
$email1 
$_GET['email'];
$email2 $email1.'x';
preg_match('|@(.*?)x|'$email2$match);
echo 
$match[1];
?>


ถ้ารับค่ามาจาก POST หรือ GET ก็อย่าลืมกัน sql injection ด้วยล่ะ
https://secrelocal.com - Local Dating Chat Rooms - No Selfie - Anonymous Sex Dating -   No Bots Dating Chat

smapan

อ้างถึงจาก: A-LAND ใน 25 ตุลาคม 2015, 11:00:02
ถ้าผมจะใช้ประมาณนี้ครับ สั้นๆ ง่ายๆ แต่ก็ใช้ได้แน่นอน

<?php
$email1 
'[email protected]';
$email2 $email1.'x';
preg_match('|@(.*?)x|'$email2$match);
echo 
$match[1];
?>


ถ้ารับค่ามาจาก POST ก็

<?php
$email1 
$_POST['email'];
$email2 $email1.'x';
preg_match('|@(.*?)x|'$email2$match);
echo 
$match[1];
?>


ถ้ารับค่าจากจาก GET

<?php
$email1 
$_GET['email'];
$email2 $email1.'x';
preg_match('|@(.*?)x|'$email2$match);
echo 
$match[1];
?>


ถ้ารับค่ามาจาก POST หรือ GET ก็อย่าลืมกัน sql injection ด้วยล่ะ

แล้วถ้าโดเมนเป็น [email protected] หรือ
อีเมล์ของ สับ โดเมน ระดับย่อยลงไปอีกล่ะครับ ??
[email protected]

เข้าใจละครับ
[direct=http://cp.siamhostweb.com/cart.php?gid=1]จูมล่าโฮส สยามโฮสเว็บ[/direct] [direct=http://www.modty.com]modty.com[/direct]
[direct=http://www.apartment.in.th]รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง[/direct]
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***