Created
October 9, 2016 01:11
-
-
Save zelon88/4cb30519c3152109a72c4dc02a9f7760 to your computer and use it in GitHub Desktop.
Made for a reddit post to help a user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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