ใช้ PHP ดึงข้อมูลเฉพาะที่ต้องการ

ประมาณนี้ครับ
$lump = 'rtyfbytgyuibg-----start-----isnv4b987b6vdc5y6ughnjmn9b8v76ctyubinn98b76r-----end-----gcgkhjkn';
$start_tag = '-----start-----';
$end_tag = '-----end-----';

// method 1
if (preg_match('/'.preg_quote($start_tag).'(.*?)'.preg_quote($end_tag).'/s', $lump, $matches)) {
    echo $matches[1];
}

// method 2 (faster)
$startpos = strpos($lump, $start_tag) + strlen($start_tag);
if ($startpos !== false) {
    $endpos = strpos($lump, $end_tag, $startpos);
    if ($endpos !== false) {
        echo substr($lump, $startpos, $endpos - $startpos);
    }
}

// method 3 (if you need to find multiple occurrences)
if (preg_match_all('/'.preg_quote($start_tag).'(.*?)'.preg_quote($end_tag).'/s', $lump, $matches)) {
    print_r($matches[1]);
}

ที่มา : http://stackoverflow.com/questions/11277620/how-to-extract-text-between-2-tags-in-php

แสดงความคิดเห็น

0 ความคิดเห็น