Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Making good use of feeds that you find

Featured Replies

Every webmaster likes a bit of free and ever changing fresh content especially if they can incorperate into a web pages HTML where those data hungry search bots can find it. RSS feeds are often ideal for this sort of thing but they can get tricky.

 

There are of course several ways to get an RSS feed into a web page however most of these methods don't play well with images in the feed and get around this by just tweeking the image source URL for the pictures simply hotlinking to the originating site.

 

Now as I'm fairly sure your all respectable and don't want some other webmaster screaming bandwidth theft read on, this little demo snippet swaps out image URL's and replaces them with the same image encoded as a base64 string that gets saved along with the regular HTML.

 

The codes not very pretty and I've not covered saving the info to database or flat file but it should hopefully give you something to experiment with.

 

 

 


<?php

$grab=1;

if ($grab==1){
$target_url= "http://en.wikinews.org/w/index.php?title=Special:NewsFeed&feed=rss&categories=Published&notcategories=No%20publish%7CArchived%7CAutoArchived%7Cdisputed&namespace=0&count=30&hourcount=124&ordermethod=categoryadd&stablepages=only";// wiki news uk
;
}


///////////////////////////////



$xml = @simplexml_load_file($target_url) or die("feed not loading"); 
//echo "<pre>"; var_dump($xml); echo "</pre>";// debug view of raw xml

foreach ($xml->channel->item as $new){
$temp_tit =  $new->title;
$temp_des =  $new->description;

$patterns = array();/// use regex to strip out any parts you don't need
$patterns[0] = '/(\r\n|\r|\n)/'; // removes line-breaks and caraige returns (makes regex simpler)
$patterns[1] = '/<div(.+?)infobox(.+?)<\/div>/'; // removes infobox div (unique to wiki news)
$patterns[2] = '/and anything else you want removing and so on/'; /// 

$replacements = array();
$replacements[0] = '';
$replacements[1] = '';
$replacements[2] = 'whatever replacement html';

$temp_des =preg_replace($patterns, $replacements, $temp_des);

/// grab all the image URL's					
$regex = '/upload(.+?)thumb(.+?)\"/';// extract images
preg_match_all($regex,$temp_des,$match);
foreach ($match as $images);


/// loop through the images
$i=0;
while ($images[$i]){
/// fetch the image from host server
$grab_link = "http://upload.wikimedia.org/wikipedia/commons/thumb".$images[$i];

//echo "grab url  ".$grab_link."</br>";

/// convert to base64 string
$image_coded =  chunk_split(base64_encode(file_get_contents($grab_link)));
if ($image_coded)	echo "image_coded success </br>";

/// add escape slashes otherwise $patterns regex throws wobbly
/// NB: command is "add C slashes" not plain addslashes
$imageSlashed = addcslashes($images[$i],'/');

//echo "image slashed".$imageSlashed."</br>";
$patterns = '/src=(.+?)'.$imageSlashed.'/';// find this html pattern

//echo "replacement pattern".$patterns."</br>+++++++++++++</br>";


$replacements =  'src="data:image/png;base64,'.$image_coded.'"';// swap in this html

/// perform swap of image src URL for base64 string
$temp_des =preg_replace($patterns, $replacements, $temp_des);	


$i++;
}

/// dumps out html
echo $temp_tit."</br>--------------------------------------</br>".$temp_des."</br>+++++++++++++++++++++++++++++++++++++++</br>";

$i++;
}					



?>

  • Author

Well that's three of us showing our age lol

 

and oops , should of posted this in server side

Edited by Sogo7

  • Author
:hi: Scoops it up with Tobermory's hat

Edited by Sogo7

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.