 |
ช่วยดูโค้ด preg_match_all หารูปจากฐานข้อมูลให้ทีครับ ว่าผมเขียนผิดไปตรงไหนครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i",$data, $matches);
print_r($matches);
ลองดูครับ
|
 |
 |
 |
 |
Date :
2011-08-18 06:14:26 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้หา HTML Tag
Code (PHP)
<?php
// The \\2 is an example of backreferencing. This tells pcre that
// it must match the second set of parentheses in the regular expression
// itself, which would be the ([\w]+) in this case. The extra backslash is
// required because the string is in double quotes.
$html = "<b>bold text</b><a href=howdy.html>click me</a>";
preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/", $html, $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
echo "matched: " . $val[0] . "\n";
echo "part 1: " . $val[1] . "\n";
echo "part 2: " . $val[2] . "\n";
echo "part 3: " . $val[3] . "\n";
echo "part 4: " . $val[4] . "\n\n";
}
?>
|
 |
 |
 |
 |
Date :
2011-08-18 06:14:54 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้เลยครับพี่วิน ผมลองเขียนแบบที่พี่แนะนำครับ
Code (PHP)
<?
$article ="<img alt='เกาะเกร็ด' src='/images/articleimages/keys307_1293071744.jpg' style='width: 450px; height: 308px;' />";
$matchs =array();
preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i", $article, $matchs);
print_r($matchs);
?>
มันแสดงแบบนี้ครับ
Array ( [0] => Array ( [0] =>
====================================
ทำได้แล้วครับ พอดีผมลืมไปว่าตัวแปร $matchs มันเป็นอาเรย์เวลาเรียกใช้ต้องแบบนี้
Code (PHP)
$matchs[1][0];
ขอบคุณอีกครั้งครับพี่ ที่เขียนมาให้ เดี๋ยวผมไปนั่งศึกษาก่อนครับว่าสัญลักษณ์แต่ละตัวทำหน้าที่อะไรบ้าง(ผมรู้แค่ไม่กี่ตัวเองครับ) ขอบคุณมากครับ 
|
ประวัติการแก้ไข 2011-08-19 00:20:31 2011-08-19 00:27:38
 |
 |
 |
 |
Date :
2011-08-19 00:18:45 |
By :
fogza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|