Skip to content

Instantly share code, notes, and snippets.

@joviczarko
Created February 3, 2017 11:06
Show Gist options
  • Save joviczarko/aff41ea1d6bbe04dfd0da74c3d26fe80 to your computer and use it in GitHub Desktop.
Save joviczarko/aff41ea1d6bbe04dfd0da74c3d26fe80 to your computer and use it in GitHub Desktop.
Load external link and parse it as XML and print some parts of it as HTML
<?php
$remote_url = 'https://example.com';
$xml = simplexml_load_file($remote_url);
$number_of_posts = 10;
?>
<ul>
<?php $i = 1; ?>
<?php foreach($xml->channel->item as $job) : ?>
<li>
<div class="jobtitle">
<h3><?php echo $job->title; ?></h3>
<a class="button" href="<?php echo $job->link; ?>" target="_blank">Go To Link</a>
</div>
<div class="jobdescription"><?php echo substr($job->description,0,230).'... '; ?><a href="<?php echo $job->link; ?>" target="_blank">More</a></div>
</li>
<?php
$i++;
if($i==$number_of_posts) break;
?>
<?php endforeach; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment