Skip to content

Instantly share code, notes, and snippets.

@zelon88
Created October 9, 2016 01:11
Show Gist options
  • Save zelon88/4cb30519c3152109a72c4dc02a9f7760 to your computer and use it in GitHub Desktop.
Save zelon88/4cb30519c3152109a72c4dc02a9f7760 to your computer and use it in GitHub Desktop.
Made for a reddit post to help a user.
<?php
// / Specify a url to xml file.
$url = 'localhost/file.xls';
// / Define a function that downloads the xml file and returns only the lines of text within it.
function getRemoteData($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data; }
// / We will now use a foreach on the file.
foreach($url as $xmlFile){
$xmlDATA = getRemoteData($xmlFile);
// / Now we can use srtpos, str_replace, and str_match
// / to create and manipulate strings from $xmlDATA.
if(strpos($xmlDATA, 'author') == true) {
//do stuff w/str_match to get the vars you want.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment