Hello guys. I have a php script which is: <?php $RSS_Content = array(); function RSS_Tags($item, $type) { $y = array(); $tnl = $item->getElementsByTagName("title"); $tnl = $tnl->item(0); $title = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("link"); $tnl = $tnl->item(0); $link = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("description"); $tnl = $tnl->item(0); $description = $tnl->firstChild->data; $y["title"] = $title; $y["link"] = $link; $y["description"] = $description; $y["type"] = $type; return $y; } function RSS_Channel($channel) { global $RSS_Content; $items = $channel->getElementsByTagName("item"); foreach($items as $item) { $y = RSS_Tags($item, 1); array_push($RSS_Content, $y); } } function RSS_Retrieve($url) { global $RSS_Content; $doc = new DOMDocument(); $doc->load($url); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { RSS_Channel($channel); } } function RSS_RetrieveLinks($url) { global $RSS_Content; $doc = new DOMDocument(); $doc->load($url); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { $items = $channel->getElementsByTagName("item"); foreach($items as $item) { $y = RSS_Tags($item, 1); // get description of article, type 1 array_push($RSS_Content, $y); } } } function RSS_Links($url, $size) { global $RSS_Content; $page = ""; RSS_RetrieveLinks($url); if($size > 0) $recents = array_slice($RSS_Content, 0, $size); foreach($recents as $article) { $type = $article["type"]; if($type == 0) continue; $title = $article["title"]; $link = $article["link"]; $page .= "<li><a href=\"$link\">$title</a></li>\n"; } $page .="</ul>\n"; return $page; } function RSS_Display($url, $size) { global $RSS_Content; $opened = false; $page = ""; RSS_Retrieve($url); if($size > 0) $recents = array_slice($RSS_Content, 0, $size); foreach($recents as $article) { $type = $article["type"]; if($type == 0) { if($opened == true) { $page .="</ul>\n"; $opened = false; } $page .="<b>"; } else { if($opened == false) { $page .= "<ul>\n"; $opened = true; } } $title = $article["title"]; $link = $article["link"]; $description = $article["description"]; $page .= "<li><a href=\"$link\">$title</a>"; if($description != false) { $page .= "<br>$description"; } $page .= "</li>\n"; if($type==0) { $page .="</b><br />"; } } if($opened == true) { $page .="</ul>\n"; } return $page."\n"; } ?> PHP: and I was wondering if I could with any way to cut the rss images from the page. Thank you, AT-XE.
I presume the script you are using is an RSS parser. Instead of building into the script a function to include images why don't you try a different RSS parser which already retrieves images such as; http://magpierss.sourceforge.net/ Alternatively you need to create a few lines of code in the function RSS_Tags() to retrieve the appropriate image URL
I am paying $7 for the code! P.S: For the other script what must I do, I downloaded it before but it was too hard for me to understand. + I want it to add the description. Thanks
function RSS_Tags($item, $type){ $y = array(); $tnl = $item->getElementsByTagName("title"); $tnl = $tnl->item(0); $title = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("link"); $tnl = $tnl->item(0); $link = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("description"); $tnl = $tnl->item(0); $description = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("image"); $tnl = $tnl->item(0); $image = $tnl->firstChild->data; $y["title"] = $title; $y["link"] = $link; $y["description"] = $description; $y["type"] = $type; $y["image"] = $image; return $y; } PHP: Try that for the first function then use $article["image"] in the last function where you are creating your "$page". Magpie RSS isn't too hard to install.
Ok, PM me your paypal and tell me what to put more, I added this code. Now what, I don't have an idea of php.
That file now looks: <?php $RSS_Content = array(); function RSS_Tags($item, $type){ $y = array(); $tnl = $item->getElementsByTagName("title"); $tnl = $tnl->item(0); $title = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("link"); $tnl = $tnl->item(0); $link = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("description"); $tnl = $tnl->item(0); $description = $tnl->firstChild->data; $tnl = $item->getElementsByTagName("image"); $tnl = $tnl->item(0); $image = $tnl->firstChild->data; $y["title"] = $title; $y["link"] = $link; $y["description"] = $description; $y["type"] = $type; $y["image"] = $image; return $y; } function RSS_Channel($channel) { global $RSS_Content; $items = $channel->getElementsByTagName("item"); foreach($items as $item) { $y = RSS_Tags($item, 1); array_push($RSS_Content, $y); } } function RSS_Retrieve($url) { global $RSS_Content; $doc = new DOMDocument(); $doc->load($url); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { RSS_Channel($channel); } } function RSS_RetrieveLinks($url) { global $RSS_Content; $doc = new DOMDocument(); $doc->load($url); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { $items = $channel->getElementsByTagName("item"); foreach($items as $item) { $y = RSS_Tags($item, 1); // get description of article, type 1 array_push($RSS_Content, $y); } } } function RSS_Links($url, $size) { global $RSS_Content; $page = ""; RSS_RetrieveLinks($url); if($size > 0) $recents = array_slice($RSS_Content, 0, $size); foreach($recents as $article) { $type = $article["type"]; if($type == 0) continue; $title = $article["title"]; $desc = $article["description"]; $link = $article["link"]; $page .= "<li><a href=\"$link\">$title</a></li>$desc\n"; } $page .="</ul>\n"; return $page; } function RSS_Display($url, $size) { global $RSS_Content; $opened = false; $page = ""; RSS_Retrieve($url); if($size > 0) $recents = array_slice($RSS_Content, 0, $size); foreach($recents as $article) { $type = $article["type"]; if($type == 0) { if($opened == true) { $page .="</ul>\n"; $opened = false; } $page .="<b>"; } else { if($opened == false) { $page .= "<ul>\n"; $opened = true; } } $title = $article["title"]; $link = $article["link"]; $article["link"] = false; $description = $article["description"]; $page .= "<li><a href=\"$link\">$title</a>"; if($description != false) { $page .= "<br>$description"; } $page .= "</li>\n"; if($type==0) { $page .="</b><br />"; } } if($opened == true) { $page .="</ul>\n"; } return $page."\n"; } ?> PHP:
There's not really much else to say... on the RSS_Display function put $article["image"] whereever you want the image to appear. As long as the URL you are using to pull in all the values has an id assigned to each image as "image" then it should work when you call the RSS_Display function.
Ahh ok, so they must be a part of the description text. You want to put this in the RSS_Tags function right after the $y["description"] = .... line of code; $y["description"] = preg_replace('#(<[/]?img.*>)#U', '', $y["description"]); PHP: