 |
อยากตัดคำใน <img......./> ใน database มาใ้ช้แสดงเป็นรูปภาพประจำหัวข้อครับ |
|
 |
|
|
 |
 |
|
ผมลองเขียนเป็น function ให้ ลองเอาไปประยุกต์ดูนะครับ
Code (PHP)
function get_img_in_str($find_str="") {
$type_img = array(".jpg",".gif",".bmp",".png");
for($i=0;$i<count($type_img);$i++) {
if(strpos($find_str,$type_img[$i])){
$pst_img = strpos($find_str, $type_img[$i]);
for($f=4;$f<strpos($find_str, $type_img[$i]);$f+=4) {
if(strpos(substr($find_str, $pst_img-$f, $pst_img-strlen($find_str)), "src=")) {
$findsrc = substr($find_str, $pst_img-$f, ($pst_img+4)-(strlen($find_str)));
$cut_src = substr($findsrc, strpos($findsrc, "src=")+4);
$path_img = explode("/", $cut_src);
$filename = end($path_img);
break;}}
break;}else{$filename="";}}
return $filename;
}
ตอนเรียกใช้งานก็ เช่น
Code
<img src="/upload/images/<?=get_img_in_str($row['content'])?>" style="height:50px; width:50px" />
|
ประวัติการแก้ไข 2014-02-22 02:05:27
 |
 |
 |
 |
Date :
2014-02-22 01:55:59 |
By :
tomrambo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|