i need some help as i am completely novice with php..
I have made a simple script to get an XML tracklist (from an API), then decode what i need and make a ul list with the tracks..
I also need to pull some artist images from a last.fm php script i found recently..
The scripts api is using http adress to get the artist and then bring up the images i found it here https://gist.github.com/iwek/5109952 and the syntax of request is : http://example.com/lastfm.php?artist=Adele
My php code for tracklist is :
foreach ($mysongs as $item):
$x = explode(" - ",$item->track);
$artist = $x[0];
$title = $x[1];
echo "<ul>$artist
$song</ul>\n";
endforeach;
Now i need to put inside the foreach the php code to generate the api call url and also include the image that this script outputs.. I am really stuck here guy's !
If anyone has any idea please do tell !
PS: keep in mind that i am really novice with php..
Thank you for your answers
$url = "http://www.example.com/lasfm.php";
$artist="Adele";
echo "$url?artist=$artist";
Related
I'm attempting to use the Zoopla API (http://developer.zoopla.com/docs/read/Property_listings) to output specific data.
I have tested the API using a simple echo after the "file_get_contents() method, which shows the data. Example code shown below (API Key Removed)
$url = "http://api.zoopla.co.uk/api/v1/property_listings.xml?postcode=CF11&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$zoopla = file_get_contents($url);
echo $zoopla;
What Im trying to code is a loop that will allow me to add html tags so that I can style them. I've done similar for a RSS feed but can't figure out a way for this XML.
I have also tried an alternative approach using simplexml_load_file()
$xml = simplexml_load_file($url);
$agent_address = $xml->agent_address->agent_address[1]->agent_address;
echo $agent_address;
Any help would be greatly appreciated!
I found the answer to my own question!
Basically the $URL is a string and not a file "simplexml_load_file()"
So first, we need to get the xml file as a string and then parse the file. Code as followed! Works like a treat!
$zoopla = file_get_contents('http://api.zoopla.co.uk/api/v1/property_listings.xml?postcode=CF64&api_key=xxxxxxxxxxxxxxxxx');
$properties = simplexml_load_string($zoopla);
echo $properties->listing[2]->agent_phone;
Wow, i hope i have written the title in a correct way, because i really have no idea how this is called.
Let me explain what i am looking for.
I have a simple application. And it contains the following:
- Frontpage (salespage)
- Admin area
- Member area
- Database to provide the app of data
I have hosted the basics of this application on a server, let's call it 'www.the.app'. And i have written it in PHP using Laravel.
Now i want to use the functions of the app, which is hosted on www.the.app and use the functions like the admin area, member area, the frontpage and create my own database on 'www.awesome.app'.
What would be the best way to make such a thing happen?
I am not looking for direct solutions. I am just looking for information to point me in the right direction to be able to make the above reality. Anything would be apreciated, like information, a name i can search on, what ever is related to this.
And if there is any more information needed, let me know please :)
Here is exactly how you can do it :
1) To Auto Login To The Site :
Note : As you will need to probably get data from login based site so you can auto login to the site through using CURL while using User Credentials with it.
To Learn How To Login Through CURL.Take A Look At :
Using PHP & Curl to login to my websites form
2) Extracting Data After Logging In Through CURL :
Note : After logging to the site now you will need to use PHP DOM to extract data from the site.So you can extract data something like this way by using PHP Simple HTML DOM Parser Library.
PHP Simple HTML DOM Parser :
LINK : http://simplehtmldom.sourceforge.net/
Sample Code For Downloading All Images From A Link :
Note : Following code will download all the images present at the URL given in the code.
<?php
// Make sure to include the library php file
include('simple_html_dom.php');
//URL To Download Images From
$url = "http://www.facebook.com/"
// Create DOM from URL or file
$html = file_get_html($url);
// Find all images
$i=1;
foreach($html->find('img') as $element) {
$url = $element->src;
$img = "/my_folder/image_".$i.".png";
file_put_contents($img, file_get_contents($url));
$i++;
}
?>
Im trying to get the url of the apple touch icon image using php but i am not successful. I found this on S.O. using this but this doesnt work either:
$html = file_get_html($url);
$img = $html->find('img[rel=apple-touch-icon]');
echo $img->href;
Any ideas on how I could accomplish this? I was thinking I could use file_get_contents() but I am not sure how to approach that.
I'm trying to use the Premium URL Shortener script from codecanyon, I have asked for support but they seem to be a little busy, so the response time is not to quick.
The issue I have is when the API sends the request to the url shortener script with the following shortened query for example purposes:
$short = "http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
Although the variables are being placed in the script correctly using echo function at the end of the script after the api request is sent shows they are correctly inserted like so:
http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan#smith.com
However if I click the shortened url provided to me from the script I only get the following url string appear in the browser:
http://myfullwebsite.com/email/quote.php?fullname=Dan
It seems as soon as there is a space or even if there is no second name such as Dan Smith and only Dan is the available name, it will not even apply the second ampersand or & sign.
I have tried to use urlecode() but still no joy and I've been pulling my hair out for the last 3 days!
As a novice beginner it has been somewhat difficult to try and achieve the end result and it seems unreachable so I would appreciate any kind help or advice if possible, Maybe I'm missing something so simple?
I've thought of having the url query build from an array of variables but as a novice I've tried one way and failed so not sure if I have done it wrong.
Here is my full api code where I have tried both with SESSION and GET but that is not the problem as the end result echos to the browser with the variables there.. it's only when you follow the shortened url link that you see they're missing.
<?php
session_start();
$fullname = htmlspecialchars($_GET["fullname"]);
$address = htmlspecialchars($_GET["address"]);
$postcode = htmlspecialchars($_GET["postcode"]);
$emailaddress = htmlspecialchars($_GET["emailaddress"]);
$short = "http://myurl/api?api=MYAPI&format=text&url=http://ukhomesurveys.co.uk/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
echo $short;
// Using Plain Text Response
$api_url = $short;
$res= #file_get_contents($api_url);
if($res){
echo $res;
}
?>
Hope I covered everything and hope I have not confused anyone. Thanks.
I think the good choice here is to encode your query with base64 and then pass it to the shortener. In your http://myfullwebsite.com/email/quote.php you just decode the query and use it. The standart PHP functions are base64_encode and base64_decode.
Did you try to encode URI using rawurlencode?
$url = rawurlencode('http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan#smith.com');
I am trying to scrape a website (believe it is in JavaScript) using a simple PHP script. I am a beginner so any help would be greatly appreciated. The URL of the webpage is:
http://www.indiainfoline.com/Markets/Company/Fundamentals/Balance-Sheet/Yes-Bank-Ltd/532648
So here for example I would like to pass the name of company (Yes-Bank-Ltd) and code (532648) in get_file_contents. Not sure on how to do it so can somebody please help.
Thanks,
Nidhi
Why aren't you just not append the string of the company and code in the url. Here is an idea that you fill up an array of company and code (need to be the same size) and then you loop them to scrape the data you want.
for($i=0;$i<count($listOfCie);$i++)
{
$cie = $listOfCie[$i];
$code = $listOfCode[$i];
$urlToScrape = "http://www.indiainfoline.com/Markets/Company/Fundamentals/Balance-Sheet/" . $cie . "/" . $code
//... = get_file_contents($urlToScrape....
}
Use the data.html table in YQL! http://developer.yahoo.com/yql/console
The simplest way to scrape a site in PHP is to use curl (http://php.net/manual/en/book.curl.php)
For some examples look at http://php.net/manual/en/curl.examples-basic.php or google :)
If the website relies on javascript though it's going to be difficult to get the data you want. You might look at a "headless browser" like http://phantomjs.org/