|
 |
|
ต้องการแยก < img > ออกมาครับ ทดสอบทดสอบ คือผมต้องการแยกรูปภาพออกจากข้อความครับ |
|
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2009-11-30 11:59:46 |
By :
neung0902 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้วิธีตัดข้อความเอาครับ
กรณีมี tag img มากกว่า 1 ควรกำหนด id ไปด้วยเพื่อจะได้ระบุถูกว่าจะตัดที่ img ไหน
Code (PHP)
$text ="<img src=\"xxx.gif\"><img id=\"imgs\" src=\"images/pic01.jpg\">";
$search =strpos($text,"id=\"imgs\""); // ค้นหา id=\"imgs\" เป็นตำแหน่งแรก
$start =strpos($text,"src",$search)+strlen("src=\""); // ค้นหาตำแหน่งแรกของคำที่จะตัด
$end=strpos($text,"\">",$start); // ค้นหาตำแหน่งสุดท้ายของคำที่จะตัด
$cut= substr($text,$start,$end-$start); //ตัดข้อความออกมา
echo $cut;
ลองศึกษา strpos() substr() เพิ่มเติมครับ
|
 |
 |
 |
 |
Date :
2009-11-30 12:12:55 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|