![]() |
|
| Domain Name Sales | Domain Software | Calculate UK Domain Drop Dates | Domain Registration | NameDrive | Domain Parking | Subscribe to our Domains For Sale newsletter |
| | ||||||
| Home | Register | Rules | Membership Upgrade | Domains For Sale | Domain Name Escrow | Mark Forums Read | Domain Classified | Chat Room |
| Scripts and Coding PHP, MySQL, scripts |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
![]() | PHP Problem
Hello, My girlfriend has uni project to create a mash up site using API's. She is looking to use an IMDB API which we have found and got it onto her site but we are having problems formating the string. The string looks as follows: http://www.deanclatworthy.com/imdb/?q=The+Green+Mile We would like to be able to use printf $movie_title, printf $movie_year etc.. Does anyone know how we can format that output to set each variable? Thanks in advance, Darren. |
| |
| | #2 (permalink) |
![]() |
Hi Darren, If the string is always the same (in terms of number of variables and their order within it) you could just <?php $movie = (the API Query); //create an array by breaking at each comma'd section $movie = explode(",". $movie); //process the new array foreach ($movie as &$value) { //create a 2 part sub array for each value $value = explode(":". $movie); //strip the label by splitting at the : and assigning the value as the second half $value=$value[1]; //remove the quotes $value = str_replace('"',"",$value); } //Leaves you with an array of the form {The Green Mile,1999,http:\/\/www.imdb.com\/title\/tt0120689\/,USA,etc etc //Set the variables $movie_title=$movie[0]; $movie_year=$movie[1]; etc etc ?> Then refer to the newly set variable as you wanted to. I've just written this out cold, so excuse any syntax errors there might be, but this should be an easy way of parsing the IMDB output. Regards Ty |
| |
| | #3 (permalink) |
![]() |
Haha, I was in the midst of writing the exact same thing Go with Ty_'s but I had made a start! I've not tried it. PHP Code: |
| |
| | #4 (permalink) |
![]() |
Looks like json to me, try this PHP: json_decode - Manual
__________________ Me: Blog | Company | Twitter Coming Soon: DaveDomains | DaveCatcher | FreeToReg.co.uk |
| |
| | #5 (permalink) | |
![]() | Quote:
| |
| |
| | #7 (permalink) | |
![]() | Quote:
Last edited by Darren; 10-01-2010 at 05:07:23 PM. | |
| |
| | #8 (permalink) |
![]() |
Here's an example: PHP Code: |
| |
| | #9 (permalink) |
| Junior Member |
Hi, Thanks for the code. I have tried to implement it but it doesnt display what you said here is my code: <form action='trial.php' method='GET'> <input type="text" name="search_term"/> <input type="submit" value="Find"/> </form> <?php // the if statement if there is nothing in the search box if(empty($_GET['search_term'])) { print "This must not be left blank!"; exit(0); } $search = $_GET['search_term']; $movie = ("http://www.deanclatworthy.com/imdb/?q="); $movie = explode(",". $movie); $string = '{ "title":"The Green Mile", "year":"1999", "imdburl":"http:\/\/www.imdb.com\/title\/tt0120689\/", "country":"USA", "languages":"English,French", "genres":"Crime,Drama,Fantasy", "rating":"http:", "votes":"179354", "usascreens":"2875", "ukscreens":"340" }'; $obj = json_decode($string); printf('<a href="%s" title="%s">%s (%d)</a>', $obj->imdburl, $obj->title, $obj->title, $obj->year); I have loads of other code that didn't work that is commented out. |
| |
| | #10 (permalink) |
![]() |
Just to mention that there's also a helpful PHP coding forum at PHP Freaks. Although I'm sure some of the members here are quite handy with PHP too ... Rgds
__________________ LowPrices.co.uk | My Twitter | KeyphraseDomains.co.uk | Mens Shirts | Hotels in Bath | Money Off Code |
| |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Domain Name Community | Replies | Last Post |
| PHP include in a Smarty Template | admin | Scripts and Coding | 1 | 13-05-2008 06:37:26 AM |
| PHP variable help | purg | General Board | 4 | 04-03-2008 02:30:21 PM |
| Problem displaying Google Adsense. | miked | Website Design | 2 | 20-07-2007 04:24:01 PM |