Getting values from specified keys - php

i use imdb api
$homepage = file_get_contents('http://www.imdbapi.com/?i='.$imdbID);
$arr = json_decode($homepage);
In $arr i have all data about related movie.
Maguire [Year] => 1996 [Rated] => R [Released] => 13 Dec 1996 [Genre] => Comedy, Drama, Romance, Sport [Director] => Cameron Crowe [Writer] => Cameron Crowe [Actors] => Tom Cruise, Cuba Gooding Jr., Renée Zellweger, Kelly Preston [Plot] => When a sports agent has a moral epiphany and is fired for expressing it, he decides to put his new philosophy to the test as an independent with the only athlete who stays with him. [Poster] => http://ia.media-imdb.com/images/M/MV5BMTkxNjc2NjQwOF5BMl5BanBnXkFtZTcwMDE2NDU2MQ##._V1_SX320.jpg [Runtime] => 2 hrs 19 mins [Rating] => 7.2 [Votes] => 97329 [ID] => tt0116695 [Response] => True )
what i want is that reaching specified key's value.
Is there a function like that? For example , i will give the key=> Actors and get all actors?

:/ Like this?
$homepage = file_get_contents('http://www.imdbapi.com/?i='.$imdbID);
$arr = json_decode($homepage, true);
print($arr['Actors']);

Related

PHP - concatenate ' checked' to each string value in multidimensional array using recursion

I have a multidimensional array in PHP, and want to concatenate a string onto each string element using recursion. The array is as follows:
$array = Array
(
[p] => Array
(
[0] => This Porsche 993 Carrera Cabriolet represents a great opportunity to acquire an open-top variant of one of the most coveted 911 models.
[1] => First registered on 5 August 1994, M912 SGY displays 10,630 miles on the odometer with a clock change at 66,244 miles in 2014.
[2] => The car’s Aventura Green metallic paintwork is reported to be in good condition, presenting well for its age and mileage.
[3] => The Marble Grey leather interior is believed to be entirely original.
[4] => Serviced by Porsche specialist Portiacraft in July 2020 at 76,598 miles, this consisted of an annual oil and filter service.
[5] => The last MOT was undertaken on 6 July 2020 at 76,598 miles.
[6] => It is supplied with a Porsche Club Great Britain folder with records of main dealer and specialist service history.
[7] => This Porsche 911 Carrera Cabriolet presents in highly original and well-maintained condition.
[8] => Summary of maintenance history:
[9] => Array
(
[strong] => The description of this auction lot is, to the best of the seller's knowledge, accurate and not misleading.
)
[10] => Array
(
[strong] => All UK-registered cars and motorbikes on Collecting Cars are run through an online HPI check. This vehicle shows no insurance database markers for damage or theft, and has no finance owing.
)
)
[ul] => Array
(
[li] => Array
(
[0] => 04/11/1996 – 16,120 miles
[1] => 18/11/1998 – 25,086 miles
[2] => 09/09/1999 – 28,769 miles
[3] => 21/02/2000 – 31,469 miles
[4] => 22/06/2001 – 36,055 miles
[5] => 29/10/2002 – 40,781 miles
[6] => 02/03/2005 – 46,238 miles
[7] => 24/03/2006 – 49,459 miles
[8] => 03/07/2007 – 53,051 miles
[9] => 17/12/2008 – 56,582 miles
[10] => 20/05/2010 – 57,385 miles
[11] => 08/06/2011 – 61,653 miles
[12] => 15/05/2012 – 64,425 miles
[13] => 17/04/2013 – 66,026 miles
[14] => 07/06/2014 – 66,244 miles
[15] => 14/09/2015 – 68,411 miles
[16] => 27/02/2018 – 74,856 miles
[17] => 06/08/2019 – ~76,400 miles
[18] => 06/07/2020 – 76,598 miles
)
)
)
Ideally, the result should look like this:
$array = Array
(
[p] => Array
(
[0] => This Porsche 993 Carrera Cabriolet represents a great opportunity to acquire an open-top variant of one of the most coveted 911 models. checked
[1] => First registered on 5 August 1994, M912 SGY displays 10,630 miles on the odometer with a clock change at 66,244 miles in 2014. checked
[2] => The car’s Aventura Green metallic paintwork is reported to be in good condition, presenting well for its age and mileage. checked
[3] => The Marble Grey leather interior is believed to be entirely original. checked
[4] => Serviced by Porsche specialist Portiacraft in July 2020 at 76,598 miles, this consisted of an annual oil and filter service. checked
[5] => The last MOT was undertaken on 6 July 2020 at 76,598 miles. checked
[6] => It is supplied with a Porsche Club Great Britain folder with records of main dealer and specialist service history. checked
[7] => This Porsche 911 Carrera Cabriolet presents in highly original and well-maintained condition. checked
[8] => Summary of maintenance history: checked
[9] => Array
(
[strong] => The description of this auction lot is, to the best of the seller's knowledge, accurate and not misleading. checked
)
[10] => Array
(
[strong] => All UK-registered cars and motorbikes on Collecting Cars are run through an online HPI check. This vehicle shows no insurance database markers for damage or theft, and has no finance owing. checked
)
)
[ul] => Array
(
[li] => Array
(
[0] => 04/11/1996 – 16,120 miles checked
[1] => 18/11/1998 – 25,086 miles checked
[2] => 09/09/1999 – 28,769 miles checked
[3] => 21/02/2000 – 31,469 miles checked
[4] => 22/06/2001 – 36,055 miles checked
[5] => 29/10/2002 – 40,781 miles checked
[6] => 02/03/2005 – 46,238 miles checked
[7] => 24/03/2006 – 49,459 miles checked
[8] => 03/07/2007 – 53,051 miles checked
[9] => 17/12/2008 – 56,582 miles checked
[10] => 20/05/2010 – 57,385 miles checked
[11] => 08/06/2011 – 61,653 miles checked
[12] => 15/05/2012 – 64,425 miles checked
[13] => 17/04/2013 – 66,026 miles checked
[14] => 07/06/2014 – 66,244 miles checked
[15] => 14/09/2015 – 68,411 miles checked
[16] => 27/02/2018 – 74,856 miles checked
[17] => 06/08/2019 – ~76,400 miles checked
[18] => 06/07/2020 – 76,598 miles checked
)
)
)
I have tried the following:
$addedChecked = $this->addCheckedRecursive($array);
private function addCheckedRecursive($array)
{
if(!is_array($array)) {
return $array . ' checked';
}
foreach($array as $v) {
$this->addCheckedRecursive($v);
}
}
and also
$addedChecked = array_walk_recursive($array, function (&$value) {
$value .= ' checked';
});
The latter simply returned true.
For info, every element of each array will always be a string, and I would also like to preserve the current array structure. Any help is appreciated.
There is an in-built function that you can use to achieve what you want.
If you use array_walk_recursive as follows:
// Say you have your array $xmlArray
array_walk_recursive($xmlArray, function (&$value) {
$value .= ' checked';
});
// Since $xmlArray is now modified (in place)
echo '<pre>';
print_r($xmlArray);
echo '</pre>';
In case you would not want $xmlArray to be changed as a side effect, could assign a value copy of the array to a new variable.
$addedChecked = $xmlArray;
array_walk_recursive($addedChecked, function (&$value) {
$value .= ' checked';
});
// Since $addedChecked is now modified (in place)
echo '<pre>';
print_r($addedChecked);
echo '</pre>';
The function takes in the array by reference and will thus modify the array directly as a side effect of the function. This is one important thing to note, it does not return an array, but only whether the function was successfully executed on the array you gave it.
This will loop over each key => value pair and do so recursively if the value is of type array. You can simply concatenate to the value (where we pass value by reference) to update it with checked.
why dont you try array_walk_recursive or array_replace_recursive ?
the docs can be found here
Try it like this:
$addedChecked = $this->addCheckedRecursive($array);
private function addCheckedRecursive($array)
{
if (!is_array($array)) {
return $array . ' checked';
}
else
{
for ($i = 0; $i < count($array); $i++) {
$array[$i] = $this->addCheckedRecursive($array[$i]);
}
return $array;
}
}

PHP extracting data from text

I have an old windows 95 program that exports data without account numbers, seasonal accounts, and if accounts contains a sub account.
I am, however, able to print customer information and notes that has the above information to a pdf file and copy that text to notepad; which I would like to extract the data.
The order the data: 1) page headers (I do not need this data.)
Company Name
Customer Information and Notes
Computed Monday, August 10 2015 Page 1
2) standard titles and 3) the data after titles:
Ser Name: Block, Sunny Route: 1
Address: 3354 ASPEN RD. Frequency: Monthly
Address: ST PETE, GA 33333 Week/Day: First Monday
City State Zip: data Sched Time (HH:MM): 10:00A
Ser Phone: 555-1212 Service: BASIC SERVICE
Bill to: BLOCK,SUNNY Rate ($): 24.00
Company Name
Customer Information and Notes
Computed Monday, August 10 2015 Page 2
Address: 1123 Sligh Terms: CASH
Address: Apt B
notes: Sunny has a mean dog
Do not enter unless dog is put up
Then it loops to next customers data and so on.
The main titles never change, such as, ser name, route, address, notes, phone. There is a set number of titles in order; however, the title notes: can take 1 -16 lines; and the header is random throughout the data. and although the titles are in order, address is titled 4 times for both service- line 1 and line 2 and billing addresses- line 1 and line 2.
I would like to set variables to these titles and only take what's after them; the extraction part through PHP. Is there anyway to do this?
I don't think it's possible for a perfect solution, but FWIW, maybe this is good enough for you.
Without a known / reliable delimiter between clients, I can't think of any good way you can get the notes without having the header stuff for the next company included, unless you can do something involving a big lookup table of all client names.
I do have (an ugly) regex that may reliably help as far as the other stuff though:
$content='[the contents of your file]';
preg_match_all('~(Ser Name|Route|Address|Frequency|Week/Day|City State Zip|Sched Time \(HH:MM\)|Ser Phone|Service|Bill to|Rate \(\$\)|Terms|notes):\s*((?:(?!Ser Name|Route|Address|Frequency|Week/Day|City State Zip|Sched Time \(HH:MM\)|Ser Phone|Service|Bill to|Rate \(\$\)|Terms|notes).)+)~is',$content,$matches);
So this basically looks for the "header" and puts into first captured group, and then matches up to the next "header" and puts that into 2nd captured group.
Perhaps this is good enough for you, but TBH I can't think of anything better you can do, unless you can improve your extraction to a better format.
So your example data would output:
Array
(
[0] => Array
(
[0] => Ser Name: Block, Sunny
[1] => Route: 1
[2] => Address: 3354 ASPEN RD.
[3] => Frequency: Monthly
[4] => Address: ST PETE, GA 33333
[5] => Week/Day: First Monday
[6] => City State Zip: data
[7] => Sched Time (HH:MM): 10:00A
[8] => Ser Phone: 555-1212
[9] => Service: BASIC SERVICE
[10] => Bill to: BLOCK,SUNNY
[11] => Rate ($): 24.00
Company Name
Customer Information and Notes
Computed Monday, August 10 2015 Page 2
[12] => Address: 1123 Sligh
[13] => Terms: CASH
[14] => Address: Apt B
[15] => notes: Sunny has a mean dog
)
[1] => Array
(
[0] => Ser Name
[1] => Route
[2] => Address
[3] => Frequency
[4] => Address
[5] => Week/Day
[6] => City State Zip
[7] => Sched Time (HH:MM)
[8] => Ser Phone
[9] => Service
[10] => Bill to
[11] => Rate ($)
[12] => Address
[13] => Terms
[14] => Address
[15] => notes
)
[2] => Array
(
[0] => Block, Sunny
[1] => 1
[2] => 3354 ASPEN RD.
[3] => Monthly
[4] => ST PETE, GA 33333
[5] => First Monday
[6] => data
[7] => 10:00A
[8] => 555-1212
[9] => BASIC SERVICE
[10] => BLOCK,SUNNY
[11] => 24.00
Company Name
Customer Information and Notes
Computed Monday, August 10 2015 Page 2
[12] => 1123 Sligh
[13] => CASH
[14] => Apt B
[15] => Sunny has a mean dog
)
)

php sort multidimensional array on date column

I have an array $dataStoreForTableImport set up in the following way.
$dataStoreForTableImport['title']
$dataStoreForTableImport['content']
$dataStoreForTableImport['date']
$dataStoreForTableImport['link']
$dataStoreForTableImport['username']
$dataStoreForTableImport['website']
It contains data as below
Array
(
[0] => Array
(
[title] => Quote from Tony Blair
[content] => ... from beating it I'm afraid." (Tony Blair, Sky News) He had every opportunity to put religion in its ...
[articledate] => 28/09/2013
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12890951
[Username] => Michael Dray
[website] => The Motley Fool
)
[1] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... I am irritated that he got such an easy ride; Why? Because he is not to your political liking? He was a witness; he was not on trial and he spoke under oath. What did you expect Jay to ask him? I had dealings with a QC a few years ago. He was as ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564154
[Username] => Michael Dray
[website] => The Motley Fool
)
[2] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... If your doubts about Jay's competence/bias were shared I'm sure it would have been debated ad nauseam on Radio 4. Eh - are you serious? I'm a Radio 4 fan - but thats despite its hatred of all things right of centre, not becuase of. ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564167
[Username] => Michael Dray
[website] => The Motley Fool
)
[3] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... Maybe Tony should have brought Cherie with him - remember Rupert Murdoch and the reaction of Wendi Deng to the custard pie incident. IMHO Cherie is every bit as intimidating:-) Wendi Deng did not eject the pie flinger, she intervened when he acted. Use of an angled bat to deflect criticism from ...
[articledate] => 30/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12565346
[Username] => Michael Dray
[website] => The Motley Fool
)
[4] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... What did surprise me was the fact that he had his own personal bodyguards in the hearing with him. Although, given the level of security that allowed that protester to break into the hearing, maybe he had a point! Eh? He is clearly at risk of terror ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564500
[Username] => Michael Dray
[website] => The Motley Fool
)
I want to be able to remove rows from this array that if the articleDate is before a given date.
I have tried everything but it does not seem to work. I am not even able to get it to sort correctly by date?
The date comes in the format - February 10, 2007
I have used
$sortDate = date('d/m/Y', strtotime($sortDate));
to format it to the format shown in the array above.
Can anyone please help?
Thanks
Mike
Do the filtering and sorting of rows in the database backend. This will improve the performance of you app. Use a WHERE clause for filtering by date and an ORDER BY clause for ordering by date in you SQL query.

check if in_array php not working

I want to check a value in an array. If its not there it gets pushed to a new array. If the value is already there then its not added to the new value.
But with my code the checking of the value is not working.
Its still adding the array if the specific value is present.
I got this code:
foreach($user_movie_info['data'] as $movie) {
similar_text($movie_facebook_page['genre'], $movie['genre'], $percent);
if ($percent > 30) {
echo $movie_facebook_page['genre']. "" ."</br>";
echo $movie['genre']. "" ."</br>";
echo $percent. "" ."</br>";
echo "match! </br></br>";
// add all movie information to matched array, only if its not already present
if (!in_array($movie_facebook_page['name'], $matched_movies_array)) {
array_push($matched_movies_array, $movie_facebook_page);
}
} //foreach
If i print out the $matched_movies_array i got one array 2 times in it:
Array
(
[0] => Array
(
[about] => In theaters January 4th 2013 www.TexasChainsaw3D.com
[can_post] => 1
[description] => Lionsgate’s TEXAS CHAINSAW 3D continues the legendary story of the homicidal Sawyer family, picking up where Tobe Hooper’s 1974 horror classic left off in Newt, Texas, where for decades people went missing without a trace. The townspeople long suspected the Sawyer family, owners of a local barbeque pit, were somehow responsible. Their suspicions were finally confirmed one hot summer day when a young woman escaped the Sawyer house following the brutal murders of her four friends. Word around the small town quickly spread, and a vigilante mob of enraged locals surrounded the Sawyer stronghold, burning it to the ground and killing every last member of the family – or so they thought.
Decades later and hundreds of miles away from the original massacre, a young woman named Heather learns that she has inherited a Texas estate from a grandmother she never knew she had. After embarking on a road trip with friends to uncover her roots, she finds she is the sole owner of a lavish, isolated Victorian mansion. But her newfound wealth comes at a price as she stumbles upon a horror that awaits her in the mansion’s dank cellars…
With gruesome surprises in store for a whole new generation, TEXAS CHAINSAW 3D stars Alexandra Daddario, Dan Yeager, Tremaine ‘Trey Songz’ Neverson, Scott Eastwood, Tania Raymonde, Shaun Sipos, Keram Malicki-Sanchez, James MacDonald, Thom Barry, Paul Rae and Richard Riehle, along with special appearances from four beloved cast members from previous installments of the franchise: Gunnar Hansen (the original Leatherface), Marilyn Burns, John Dugan and Bill Moseley. The film is directed by John Luessenhop (TAKERS), from a screenplay by Adam Marcus & Debra Sullivan and Kirsten Elms, based on a story by Stephen Susco and Adam Marcus & Debra Sullivan and based on characters created by Kim Henkel and Tobe Hooper, and produced by Carl Mazzocone. Lionsgate presents a production and Main Line Pictures production.
[directed_by] => John Luessenhop
[genre] => Horror
[is_published] => 1
[produced_by] => Millennium Films
[release_date] => January 4th 2012
[screenplay_by] => Adam Marcus & Debra Sullivan and Kirsten Elms
[starring] => Alexandra Daddario, Dan Yeager, Tremaine ‘Trey Songz’ Neverson, Scott Eastwood, Tania Raymonde, Shaun Sipos, Keram Malicki-Sanchez, James MacDonald, Thom Barry, Paul Rae and Richard Riehle
[studio] => Lionsgate
[talking_about_count] => 62964
[username] => TexasChainsaw3D
[website] => www.texaschainsaw3d.com, twitter.com/lionsgatehorror, http://pinterest.com/lionsgatemovies/texas-chainsaw-3d, https://plus.google.com/u/0/+LionsgateMovies, http://instagr.am/p/Qpm0JMPtDr/
[were_here_count] => 0
[written_by] => based on a story by Stephen Susco and Adam Marcus & Debra Sullivan
[category] => Movie
[id] => 323192834416509
[name] => Texas Chainsaw 3D
[link] => http://www.facebook.com/TexasChainsaw3D
[likes] => 367992
[cover] => Array
(
[cover_id] => 4.14284428641E+14
[source] => http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/s720x720/530974_414284428640682_1806025466_n.png
[offset_y] => 0
)
)
[1] => Array
(
[about] => The official Facebook Page for The Shining | All work and no play makes Jack a dull boy.
[awards] => (1981) Saturn Award, Best Supporting Actor, Scatman Crothers
[can_post] => 1
[description] => Get The Shining at the WB Shop: http://bit.ly/shiningdvd
[directed_by] => Stanley Kubrick
[genre] => Horror, Suspense/Thriller
[is_published] => 1
[plot_outline] => All work and no play makes Academy Award-winner Jack Nicholson ("As Good As It Gets," "Batman"), the caretaker of an isolated resort, go way off the deep end, terrorizing his young son and wife Shelley Duvall ("Roxanne"). Master filmmaker Stanley Kubrick's ("Full Metal Jacket," "2001: A Space Odyssey") visually haunting chiller, based on the bestseller by master-of-suspense Stephen King ("The Stand," "Carrie," "The Shawshank Redemption"), is an undeniable contemporary classic. Newsweek Magazine calls this "the first epic horror film," full of indelible images, and a signature role for Nicholson whose character was recently selected by AFI for its' 50 Greatest Villains.
[produced_by] => Jan Harlan, Stanley Kubrick
[release_date] => 5/23/80
[screenplay_by] => Stephen King, Diane Johnson
[starring] => Jack Nicholson, Shelley Duvall, Danny Lloyd, Scatman Crothers
[studio] => Warner Bros.
[talking_about_count] => 5594
[username] => KubrickShining
[website] => http://bit.ly/shiningdvd
[were_here_count] => 0
[written_by] => Stephen King
[category] => Movie
[id] => 135347089926692
[name] => The Shining
[link] => http://www.facebook.com/KubrickShining
[likes] => 832526
[cover] => Array
(
[cover_id] => 2.24275514367E+14
[source] => http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash4/320182_224275514367182_46004854_n.jpg
[offset_y] => 85
)
)
[2] => Array
(
[about] => The official Facebook Page for The Shining | All work and no play makes Jack a dull boy.
[awards] => (1981) Saturn Award, Best Supporting Actor, Scatman Crothers
[can_post] => 1
[description] => Get The Shining at the WB Shop: http://bit.ly/shiningdvd
[directed_by] => Stanley Kubrick
[genre] => Horror, Suspense/Thriller
[is_published] => 1
[plot_outline] => All work and no play makes Academy Award-winner Jack Nicholson ("As Good As It Gets," "Batman"), the caretaker of an isolated resort, go way off the deep end, terrorizing his young son and wife Shelley Duvall ("Roxanne"). Master filmmaker Stanley Kubrick's ("Full Metal Jacket," "2001: A Space Odyssey") visually haunting chiller, based on the bestseller by master-of-suspense Stephen King ("The Stand," "Carrie," "The Shawshank Redemption"), is an undeniable contemporary classic. Newsweek Magazine calls this "the first epic horror film," full of indelible images, and a signature role for Nicholson whose character was recently selected by AFI for its' 50 Greatest Villains.
[produced_by] => Jan Harlan, Stanley Kubrick
[release_date] => 5/23/80
[screenplay_by] => Stephen King, Diane Johnson
[starring] => Jack Nicholson, Shelley Duvall, Danny Lloyd, Scatman Crothers
[studio] => Warner Bros.
[talking_about_count] => 5594
[username] => KubrickShining
[website] => http://bit.ly/shiningdvd
[were_here_count] => 0
[written_by] => Stephen King
[category] => Movie
[id] => 135347089926692
[name] => The Shining
[link] => http://www.facebook.com/KubrickShining
[likes] => 832526
[cover] => Array
(
[cover_id] => 2.24275514367E+14
[source] => http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash4/320182_224275514367182_46004854_n.jpg
[offset_y] => 85
)
)
)
I get this info from the open graph api from Facebook.
$matched_movies_array does not contain the movie names. So in_array will never pass.
Try something like:
$movieIds = array();
foreach($user_movie_info['data'] as $movie) {
similar_text($movie_facebook_page['genre'], $movie['genre'], $percent);
if ($percent > 30) {
echo $movie_facebook_page['genre']. "" ."</br>";
echo $movie['genre']. "" ."</br>";
echo $percent. "" ."</br>";
echo "match! </br></br>";
// add all movie information to matched array, only if its not already present
if (!in_array($movie_facebook_page['id'], $movieIds)) {
$movieIds[] = $movie_facebook_page['id'];
array_push($matched_movies_array, $movie_facebook_page);
}
} //foreach
Or maybe even better:
$id = $movie_facebook_page['id'];
if (!isset($matched_movies_array[$id])) {
$matched_movies_array[$id] = $movie_facebook_page;
}
The in_array() function doesn't work searching for a string in a multi-dimensional array. Take this for example:
$find = array("name" => "test");
$matches = array(array("name" => "test"), array("name" => "test2"));
echo (in_array($find['name'], $matches)) ? "found" : "not found";
echo "<br /><br />";
echo (in_array($find, $matches)) ? "found" : "not found";
The first echo is "not found", the second one is "found". You should use your entire $movie_facebook_page array as the needle.

Retrieving BIO information in LastFM API and PHP

I'm trying to look up the artist BIO information with the LASTFM api but I'm having trouble.
I'm using PHP and a CURL request that's returning the result as XML.
If I use the url that gets sent by CURL and just load it normally in the browser it show's everything as desired. However, the result returned by CURL in the php script is missing certain properties of the XML.
For example: artist->bio->summary is there but with no content.
You can replicate what I'm doing ill copy the basic concepts here:
open this in you browser:
http://ws.audioscrobbler.com/2.0/artist/cher/info.xml
copy and paste this into a PHP file and open:
$url = 'http://ws.audioscrobbler.com/2.0/artist/cher/info.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$retData = curl_exec($ch);
curl_close($ch);
echo '<pre>';
echo $retData;
echo '</pre>';
You'll see that the returned results are similar but with missing content in the curl request. I've also tried doing this a simplexml_load_file() but the same happens. What am I missing? Cheers for any help!
Try to replace
echo $retData;
with
echo htmlspecialchars($retData);
and you'll see that everything is there. You're printing raw XML in an HTML context, and some of the tags in the XML are interpreted as HTML tags.
The url is wrong but that could be a typo ;p. The reason its content is missing is the <![CDATA[ tag, strip it before parsing and you should be good to go.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ws.audioscrobbler.com/2.0/artist/cher/info.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$retData = curl_exec($ch);
$retData = str_replace(array('<![CDATA[',']]>'),'',$retData);
$xml = simplexml_load_string($retData);
$lastFM = json_decode(json_encode($xml),TRUE);
print_r($lastFM);
/*Array
(
[name] => Cher
[mbid] => bfcc6d75-a6a5-4bc6-8282-47aec8531818
[url] => http://www.last.fm/music/Cher
[image] => Array
(
[0] => http://userserve-ak.last.fm/serve/34/63530405.png
[1] => http://userserve-ak.last.fm/serve/64/63530405.png
[2] => http://userserve-ak.last.fm/serve/126/63530405.png
[3] => http://userserve-ak.last.fm/serve/252/63530405.png
[4] => http://userserve-ak.last.fm/serve/500/63530405/Cher.png
)
[streamable] => 1
[stats] => Array
(
[listeners] => 768175
[playcount] => 7895613
)
[similar] => Array
(
[artist] => Array
(
[0] => Array
(
[name] => Sonny & Cher
[url] => http://www.last.fm/music/Sonny+&+Cher
[image] => Array
(
[0] => http://userserve-ak.last.fm/serve/34/71168880.png
[1] => http://userserve-ak.last.fm/serve/64/71168880.png
[2] => http://userserve-ak.last.fm/serve/126/71168880.png
[3] => http://userserve-ak.last.fm/serve/252/71168880.png
[4] => http://userserve-ak.last.fm/serve/500/71168880/Sonny++Cher.png
)
)
[1] => Array
(
[name] => Cyndi Lauper
[url] => http://www.last.fm/music/Cyndi+Lauper
[image] => Array
(
[0] => http://userserve-ak.last.fm/serve/34/76056286.png
[1] => http://userserve-ak.last.fm/serve/64/76056286.png
[2] => http://userserve-ak.last.fm/serve/126/76056286.png
[3] => http://userserve-ak.last.fm/serve/252/76056286.png
[4] => http://userserve-ak.last.fm/serve/_/76056286/Cyndi+Lauper++for+Uniqlo.png
)
)
[2] => Array
(
[name] => Madonna
[url] => http://www.last.fm/music/Madonna
[image] => Array
(
[0] => http://userserve-ak.last.fm/serve/34/78270650.png
[1] => http://userserve-ak.last.fm/serve/64/78270650.png
[2] => http://userserve-ak.last.fm/serve/126/78270650.png
[3] => http://userserve-ak.last.fm/serve/252/78270650.png
[4] => http://userserve-ak.last.fm/serve/_/78270650/Madonna+Shes+a+bad+girl.png
)
)
[3] => Array
(
[name] => Kylie Minogue
[url] => http://www.last.fm/music/Kylie+Minogue
[image] => Array
(
[0] => http://userserve-ak.last.fm/serve/34/78217522.png
[1] => http://userserve-ak.last.fm/serve/64/78217522.png
[2] => http://userserve-ak.last.fm/serve/126/78217522.png
[3] => http://userserve-ak.last.fm/serve/252/78217522.png
[4] => http://userserve-ak.last.fm/serve/500/78217522/Kylie+Minogue+KylieBestOf.png
)
)
[4] => Array
(
[name] => Tina Turner
[url] => http://www.last.fm/music/Tina+Turner
[image] => Array
(
[0] => http://userserve-ak.last.fm/serve/34/74998404.jpg
[1] => http://userserve-ak.last.fm/serve/64/74998404.jpg
[2] => http://userserve-ak.last.fm/serve/126/74998404.jpg
[3] => http://userserve-ak.last.fm/serve/252/74998404.jpg
[4] => http://userserve-ak.last.fm/serve/_/74998404/Tina+Turner+Queen+3.jpg
)
)
)
)
[tags] => Array
(
[tag] => Array
(
[0] => Array
(
[name] => pop
[url] => http://www.last.fm/tag/pop
)
[1] => Array
(
[name] => female vocalists
[url] => http://www.last.fm/tag/female%20vocalists
)
[2] => Array
(
[name] => 80s
[url] => http://www.last.fm/tag/80s
)
[3] => Array
(
[name] => dance
[url] => http://www.last.fm/tag/dance
)
[4] => Array
(
[name] => rock
[url] => http://www.last.fm/tag/rock
)
)
)
[bio] => Array
(
[published] => Tue, 1 May 2012 12:51:56 +0000
[summary] => Cher (born Cherilyn Sarkisian on May 20, 1946) is an American singer, actress, songwriter, author and entertainer. Among her many career accomplishments in music, television and film, she has won an Academy Award, a Grammy Award, an Emmy Award and three Golden Globe Awards among others. Referred to as the Goddess of Pop, Cher first rose to prominence in 1965 as one half of the pop/rock duo Sonny & Cher.
[content] => Cher (born Cherilyn Sarkisian on May 20, 1946) is an American singer, actress, songwriter, author and entertainer. Among her many career accomplishments in music, television and film, she has won an Academy Award, a Grammy Award, an Emmy Award and three Golden Globe Awards among others.
Referred to as the Goddess of Pop, Cher first rose to prominence in 1965 as one half of the pop/rock duo Sonny & Cher. She also established herself as a solo recording artist, releasing 25 albums, contributing to numerous compilations, and tallying 34 Billboard Top 40 entries over her career, both solo and with Sonny. These include eighteen Top 10 singles and five number one singles (four solo). Cher has had 16 top ten hits in the UK between 1965 and 2003, four of which reached number one (two solo, one with Sonny, one as part of a charity single).
In a career surpassing 40 years, Cher has been described as an enduring pop icon and one of the most popular female artists in music history. Since her debut in 1964, Cher has sold as a solo artist over 180 million records worldwide and an estimated 70 million singles and with duo Sonny and Cher over 80 million records becoming one of the biggest-selling artists of all time.
She became a television star in the 1970s and a film actress in the 1980s. In 1987, she won the Academy Award for Best Actress for her role in the romantic comedy Moonstruck.
During 2007, in the seventh volume of Chrome Hearts, Cher once again confirmed that she is working on her twenty-sixth studio album. No recordings have taken place as of yet, and no release date had been scheduled.
It is rumoured that Cher will collaborate with Lady Gaga in a song for her next album Born This Way. This album is expected to be released in Spring 2011.
On February 7, 2008 Cher, at 61, announced that she had reached a deal to perform 200 shows over three years live at the Colosseum at Caesar's Palace in Las Vegas. Her new show, entitled Cher at the Colosseum, debuted on May 6, 2008. The show reportedly includes 18 dancers, 4 aerialists, and multiple costumes designed by Bob Mackie. Choreography will be directed by Doriana Sanchez who also worked with Cher on her past three major tours. Her show will perform four nights a week for a month, and a second leg of the show will continue in August. Cher will share the stage on a rotating basis with contemporaries Bette Midler (whose The Showgirl Must Go On opened on February 20, 2008) and Elton John (whose The Red Piano which opened in 2004, will continues its run of about 50 shows a year).
Cher made her musical debut and first film role in a decade in , starring alongside Christina Aguilera, who also made her musical and film debut. The film was released in November 2010.
User-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.
)
)
*/

Categories