Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ดึงลิงค์ url จากใน CDATA ได้ไหมครับ พี่ ๆ แนะนำหน่อยนะครับ(มีตัวอย่าง)



 

ดึงลิงค์ url จากใน CDATA ได้ไหมครับ พี่ ๆ แนะนำหน่อยนะครับ(มีตัวอย่าง)

 



Topic : 091268



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



อันนี้โครงสร้าง xml ครับของที่จะดึงข้อมูล

Code
<item>
<title><![CDATA[ABCDEFG]]></title>
<link><![CDATA[http://www.XXXXX.net/detail/aaaaa/aaaaa/XXX.html]]></link>
<description><![CDATA[HHHHHHHHHHHHHHHHHHHHHHHHHHH]]></description>
<pubDate>Fri, 22 Feb 2013 06:00:25 </pubDate>
<enclosure url="http://www.XXXXXXX.net/media/img/size4/2013/02/21/XXXXXXXXXXXXX.jpg" type="image/jpeg"/>
</item>







ตอนนี้มันดึงจากอันนี้ได้ครับ


Code
<item>
<title>XXXXXXXXXXXXXXXXXXXXXXXXX</title>
<guid isPermaLink="false">http://www.thairath.co.th/content/eco/328182</guid>
<description>"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx</description>
<link>http://www.XXXXX.com/XXXXX/XXX/XXXXX</link>
<enclosure url="/XXX/XXX/XXX/02/21/328182/XXXXXX/XXX.jpg" type="image/jpeg"/>
<pubDate>Fri, 22 Feb 2013 05:30:00 +0700</pubDate>
</item>



อันนี้สคลิปที่ใช้ครับ

Code
<?php

if(!defined('IN_DISCUZ')) {

exit('Access Denied');

}



include("kom_config.inc.php");



$rss_post_dir = DISCUZ_ROOT . './data/rss_post';

if(!is_dir($rss_post_dir)) mkdir($rss_post_dir,0777);

if(!is_dir($rss_post_dir.'/mark')) mkdir($rss_post_dir.'/mark',0777);

//if(!is_dir($rss_post_dir.'/images')) mkdir($rss_post_dir.'/images',0777);





if (!isset($kom['data'])) {

return;

}

foreach ($kom['data'] as $dd) {

$count=0;

if (isset($dd['rss'])&&isset($dd['fid'])) {

$dom = new DOMDocument();

if ($dom->load($dd['rss'])) {

$datas = $dom->getElementsByTagName("item");

foreach($datas as $data) {

$attach_img=array();

if (isset($dd['limit'])&&$count>=$dd['limit']) {break;}

$title = trim($data->getElementsByTagName("title")->item(0)->nodeValue);

$link = trim($data->getElementsByTagName("link")->getElementsByTagName("CDATA")->item(0)->nodeValue);

if (isset($dd['keywords'])&&count($dd['keywords'])>0) {

$skip=1;

foreach ($dd['keywords'] as $k) {

if (preg_match("/{$k}/i",$title)) {

$skip=0;

}

}

if ($skip==1) {continue;}

}

if (!isset($dd['content_var'])||$dd['content_var']=='') {$dd['content_var']='description';}

if (preg_match("/^(.+):(.+)$/",$dd['content_var'],$match)) {

$description = trim($data->getElementsByTagNameNS('*',$match[2])->item(0)->nodeValue);

if ($description=='') {return;}

} else {

$description = trim($data->getElementsByTagName($dd['content_var'])->item(0)->nodeValue);

}

if (isset($dd['convert_bbcode'])&&$dd['convert_bbcode']=='1') {

$description = BBCODE($description);

// cache image

$arr=preg_match_all("|(\[img\]([^>]+)\[\/img\])|U",$description,$match,PREG_SET_ORDER);

if (count($match)>0) {

$markfile=DISCUZ_ROOT . './data/rss_post/mark/'.parse_url($link,PHP_URL_HOST).'.txt';

if(!file_exists($markfile)||strpos(file_get_contents($markfile) ,$link) === false){
foreach ($match as $img) {

$imgpath=DISCUZ_ROOT . './data/attachment/forum';

if(!is_dir($imgpath.'/'.date('Ym'))) make_dir($imgpath.'/'.date('Ym'));

if(!is_dir($imgpath.'/'.date('Ym').'/'.date('d'))) make_dir($imgpath.'/'.date('Ym').'/'.date('d'));

$imagedata = file_get_contents($img[2]);

$ext = addslashes(strtolower(substr(strrchr($img[2], '.'), 1, 10)));

$filename = strtolower(substr(strrchr($img[2], '/'), 1));

$attachment=date('Ym').'/'.date('d').'/'.date('His').strtolower(random(16)).'.'.$ext;

$imagefile = $imgpath.'/'.$attachment;

$imageurl = $_G['siteurl'] .(substr($_G['siteurl'],-1)=='/'?'':'/').$imagefile;

$f = fopen($imagefile,'w');

fwrite($f,$imagedata);

fclose($f);

list($width, $height, $type, $attr) = getimagesize($imagefile);

// insert new image



$arr = array(

'tid'=>0,

'pid'=>0,

'uid'=>0,

'tableid'=>0,

'downloads'=>0,

);

DB::insert('forum_attachment',$arr);

$aid = DB::insert_id();

// edit content

$description=str_replace("{$img[1]}","[attach]{$aid}[/attach]",$description);

// queue order

$attach_img[] = array(

'aid'=>$aid,

'filename'=>$filename,

'filesize'=>filesize($imagefile),

'attachment'=>$attachment,

'width'=>$width

);

}

}

}

}

$description = addslashes($description);



if (!isset($dd['image_var'])||$dd['image_var']=='') {$image='';} else {

if ($domDocument->getElementsByTagName($dd['image_var'])->length!=0)

{

$image=trim($data->getElementsByTagName($dd['image_var'])->item(0)->getAttribute('url'));

} else {$image='';}

}

$time = strtotime(trim($data->getElementsByTagName("pubDate")->item(0)->nodeValue));

$title = str_replace(array('\\','\''),array('\\\\','\\\''),$title);

$markfile=DISCUZ_ROOT . './data/rss_post/mark/'.parse_url($link,PHP_URL_HOST).'.txt';

if(!file_exists($markfile)||strpos(file_get_contents($markfile) ,$link) === false){

$f = fopen($markfile,'a');

fwrite($f,$link."\n");

fclose($f);

if ($dd['module']==''||!isset($dd['module'])) {

$content = $description;

$content.= '



ขอบคุณข่าวจาก : <a class="external" rel="nofollow" href="/outling.php?l=http://'.parse_url($link,PHP_URL_HOST).'" target="blank" title="'.parse_url($link,PHP_URL_HOST).'">'.parse_url($link,PHP_URL_HOST).'</a>';

} elseif ($dd['module']=='kom') {

$image=trim($data->getElementsByTagName('enclosure')->item(0)->getAttribute('url'));

$image = str_replace('120.jpg','630.jpg',$image);

$content = file_get_contents($link);

$content = explode('<div id="details" class="page">',$content);

$content = $content[1];

$content = explode('</p></p>',$content);

$content = $content[0];

$content = str_replace(array('\\','\'','<br />','</p>'),array('\\\\','\\\'',"\r\n","\r\n"),$content);

$content = strip_tags($content);

$content.='';

}

// save image

if ($image!='') {

$imgpath=DISCUZ_ROOT . './data/attachment/forum';

if(!is_dir($imgpath.'/'.date('Ym'))) make_dir($imgpath.'/'.date('Ym'));

if(!is_dir($imgpath.'/'.date('Ym').'/'.date('d'))) make_dir($imgpath.'/'.date('Ym').'/'.date('d'));

$imagedata = file_get_contents($image);

$ext = addslashes(strtolower(substr(strrchr($image, '.'), 1, 10)));

$filename = strtolower(substr(strrchr($img[2], '/'), 1));

$attachment=date('Ym').'/'.date('d').'/'.date('His').strtolower(random(16)).'.'.$ext;

$imagefile = $imgpath.'/'.$attachment;

$imageurl = $_G['siteurl'] .(substr($_G['siteurl'],-1)=='/'?'':'/').$imagefile;

$f = fopen($imagefile,'w');

fwrite($f,$imagedata);

fclose($f);

list($width, $height, $type, $attr) = getimagesize($imagefile);

// insert new image

$arr = array(

'tid'=>0,

'pid'=>0,

'uid'=>0,

'tableid'=>0,

'downloads'=>0,

);

DB::insert('forum_attachment',$arr);

$aid = DB::insert_id();

// edit content

$content = '[attach]'.$aid.'[/attach]'.$content;

// queue order

$attach_img[] = array(

'aid'=>$aid,

'filename'=>$filename,

'filesize'=>filesize($imagefile),

'attachment'=>$attachment,

'width'=>$width

);



}



$count++;

$poster = DB::result_first("SELECT username FROM ".DB::table('common_member')." WHERE uid='{$kom['poster_uid']}'");

$arr = array(

'fid'=>$dd['fid'],

'author'=>$poster,

'authorid'=>$kom['poster_uid'],

'subject'=>$title,

'dateline'=>$time,

'lastpost'=>$time,

'lastposter'=>$poster,

'status'=>32,

'stamp'=>-1,

'icon'=>-1,

);

DB::insert('forum_thread',$arr);

$tid = DB::insert_id();



$pid = insertpost(array(

'fid'=>$dd['fid'],

'tid'=>$tid,

'first'=>1,

'author'=>$poster,

'authorid'=>$kom['poster_uid'],

'subject'=>$title,

'dateline'=>$time,

'message'=>$content,

'useip'=>'127.0.0.1',

'invisible'=>0,

'anonymous'=>0,

'usesig'=>1,

'htmlon'=>1,

'bbcodeoff'=>0,

'smileyoff'=>0,

'parseurloff'=>0,

'attachment'=>'0',

'tags'=>'',

));

DB::query("UPDATE ".DB::table('forum_forum')." SET threads=threads+1,posts=posts+1,todayposts=todayposts+1,lastpost='".strval($tid) .' '.$title .' '.$time .' '.$poster."' WHERE fid='{$dd['fid']}'", 'UNBUFFERED');

DB::query("UPDATE ".DB::table('common_member_count')." SET posts=posts+1,threads=threads+1 WHERE uid='{$kom['poster_uid']}'", 'UNBUFFERED');

$first_img=0;

// insert image

foreach ($attach_img as $ai) {



$tableid=$tid%10;

DB::query("UPDATE ".DB::table('forum_attachment')." SET tid='{$tid}',pid='{$pid}',uid={$kom['poster_uid']},tableid='{$tableid}' WHERE aid='{$ai['aid']}'", 'UNBUFFERED');

$arr = array(

'aid'=>$ai['aid'],

'tid'=>$tid,

'pid'=>$pid,

'uid'=>$kom['poster_uid'],

'dateline'=>$_G['timestamp'],

'filename'=>$ai['filename'],

'filesize'=>$ai['filesize'],

'attachment'=>$ai['attachment'],

'remote'=>0,

'description'=>'',

'readperm'=>0,

'price'=>0,

'isimage'=>1,

'width'=>$ai['width'],

'thumb'=>0,

'picid'=>0

);

DB::insert('forum_attachment_'.$tableid,$arr);

DB::query("UPDATE ".DB::table('forum_post')." SET attachment=attachment+1 WHERE pid='{$pid}'", 'UNBUFFERED');

DB::query("UPDATE ".DB::table('forum_thread')." SET attachment=attachment+1 WHERE tid='{$tid}'", 'UNBUFFERED');

if ($first_img==0) {

DB::insert('forum_threadimage', array(

'tid' => $tid,

'attachment' => $ai['attachment'],

'remote' => 0

));

$first_img=1;

}

}

}

}

} else {

}

}

}

function ()

{

$bbcode = array(

"/\<([bius])\>/is" => "[$1]",

"/\<center\>/is" => "[align=center]",

"/\<\/center\>/is" => "[/align]",

"/\<strong\>/is" => "",

"/\<\/strong\>/is" => "",

"/\<em\>/is" => "<i>",

"/\<\/em\>/is" => "</i>",

"/\<code\>/is" => "<div>",

"/\<\/code\>/is" => "</font></div>",

"/\<small\>/is" => "<small>",

"/\<\/small\>/is" => "</small>",

"/\<script[^>]*\>.*\<\/script\>/is" => "",

"/\<font[^>]*\>/is" => "",

"/\<h([0-9]+)[^>]*\>/" => "[h$1]",

"/\<\/h([0-9]+)[^>]*\>/" => "[/h$1]",

"/\<\/font\>/is" => "",

"/\<span[^>]*\>/is" => "",

"/\<\/span\>/is" => "",

"/\<table[^>]*\>/is" => "[table=50%]",

"/\<\/table\>/is" => "[/table]",

"/\<\/tr\>/is" => "[/tr]",

"/\<\/td\>/is" => "[/td]",

"/\<tr[^>]*\>/is" => "[tr]",

"/\<td[^>]*\>/is" => "[td]",

"/\<div[^>]*\>/is" => "[p=30, 2, left]",

"/\<\/div\>/is" => "[/p]",

"/\<p[^>]*>/is" => "[p=30, 2, left]",

"/\<\/p\>/is" => "[/p]",

"/\<img[^>]*src=[\"\']([^\s'\"<>]+)[\"\'][^>]*\>/is" => "<img src=$1>",
"/\<\/img\>/is" => "[/img]",

"/\<a[^>]*href=[\"\']([^\s'\"<>]+)[\"\'][^>]*\>/is" => "[url=$1]",
"/\<\/a\>/is" => "[/url]",

"/\<ol[^>]*\>/is" => "[list=1]",

"/\<ul[^>]*\>/is" => "<ul>",

"/\<li[^>]*\>/is" => "[*]",

"/\<\/li\>/is" => "",

"/\<\/ul\>/is" => "</ul>",

"/\<\/ol\>/is" => "[/list]",

"/\<br[^>]*\>/is" => "\n",

"/\<blockquote[^>]*\>/is" => "<div style=padding-left:20px><blockquote><strong>Quote:</strong><div class=code>",

"/\<\/blockquote\>/is" => "</div></blockquote></div>",
"/\<\/blockquote\>/is" => "[/quote]",

"/\<object[^>]*\>/is" => "",

"/\<\/object\>/is" => "",

"/\<param[^>]*\>/is" => "",

"/\<\/param\>/is" => "",

"/\<embed[^>]*src=[\"\'](http\:\/\/www\.youtube\.com\/watch\?v\=\/[^\s'\"<>]+)[\"\'][^>]*\>/is" => "[media=x,500,375]$1[/media]",

"/\<embed[^>]*src=[\"\']http\:\/\/www\.youtube\.com\/v\/([^\s'\"<>]+)[\"\'][^>]*\>/is" => "[media=x,500,375]http://www.youtube.com/watch?v=$1[/media]"

);



$text = preg_replace(array_keys($bbcode), array_values($bbcode), $input);



$strfind = array('&nbsp;', '&lt;', '&gt;', '&amp;');

$strreplace = array(' ', '<', '>', '&');

$text = str_replace($strfind, $strreplace, $text);



return htmlspecialchars_decode($text);

}

function make_dir($dir, $index = true) {

$res = true;

if(!is_dir($dir)) {

$res = @mkdir($dir, 0777);

$index && @touch($dir.'/index.html');

}

return $res;

}

?>






ช่วยแนะนำหน่อยนะครับว่า ถ้าจะดึงข้อมูลจากใน tag <link><+[CDATA[http://www.XXXXX.net/detail/aaaaa/aaaaa/XXX.html]]></link>

จะต้องเพิ่มส่วนไหนเข้าไป ผมศึกษาอยู่ แต่จากสคลิปค่อนข้างจะยากเกินสำหรับมือใหม่อย่างผม ยังไงต้องขอคำแนะนำจากผู้มีประสบการณ์ด้วยครับ



Tag : PHP









ประวัติการแก้ไข
2013-02-22 10:00:51
2013-02-22 10:02:38
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-02-22 09:09:28 By : thatcharuam View : 5170 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เอา Script มาจากไหนครับ เขียนซะยาวเลยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-22 16:11:49 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ดึงลิงค์ url จากใน CDATA ได้ไหมครับ พี่ ๆ แนะนำหน่อยนะครับ(มีตัวอย่าง)
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่