Buy Sell Discuss UK Domain Names at AcornDomains.co.uk Free Virtual Servers

Today's Drop Dates are: 07-11-2011 or 14-11-2011   All times are GMT. The time now is 01:24:50 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design > Scripts and Coding
Connect with Facebook

Scripts and Coding PHP, MySQL, scripts

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 10-01-2010, 12:51:58 PM     #1 (permalink)

 
Darren's Avatar
 
Join Date: Feb 2008
Location: Kent
Posts: 1,765
Darren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond repute

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.
Darren is offline  
Old 10-01-2010, 01:20:37 PM     #2 (permalink)

 
Join Date: Jul 2009
Posts: 1,323
retired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond reputeretired_member13 has a reputation beyond repute

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
retired_member13 is offline  
Old 10-01-2010, 01:36:45 PM     #3 (permalink)
dtm

 
dtm's Avatar
 
Join Date: Jan 2009
Location: Cheshire / Warwickshire
Posts: 768
dtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond repute

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:
<?

$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"}';

$items explode(',',$string);

foreach(
$items as $item){
    
$temp explode(':',$item);

    
$key $temp[0];
    
$var $temp[1];
    
    
$key str_replace("{","",$key);
    
$key str_replace('"','',$key);
    
    
$var str_replace("{","",$var);
    
$var str_replace('"','',$var);
    
$var str_replace(',','',$var);
    
    
$array[$key] = $var;
    
}


?>
__________________
Club Classics - ASCII - YMN
dtm is offline  
Old 10-01-2010, 01:47:18 PM     #4 (permalink)

 
davedevelopment's Avatar
 
Join Date: May 2009
Location: Brough, East Yorks
Posts: 988
davedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond repute

Looks like json to me, try this PHP: json_decode - Manual
__________________
Me: Blog | Company | Twitter

Coming Soon: DaveDomains | DaveCatcher | FreeToReg.co.uk
davedevelopment is online now  
Old 10-01-2010, 01:59:34 PM     #5 (permalink)
dtm

 
dtm's Avatar
 
Join Date: Jan 2009
Location: Cheshire / Warwickshire
Posts: 768
dtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond repute

Quote:
Originally Posted by davedevelopment View Post
Looks like json to me, try this PHP: json_decode - Manual
Thats just far too easy
dtm is offline  
Old 10-01-2010, 04:48:14 PM     #6 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

Php Problem

Hello Everyone,

I am the girlfriend with the Php Problem. I have tried using the JSON, I think I need to elaborate on it as it isn't doing anything different at the moment.

Thanks.
Betty Boop is offline  
Old 10-01-2010, 05:00:30 PM     #7 (permalink)

 
Darren's Avatar
 
Join Date: Feb 2008
Location: Kent
Posts: 1,765
Darren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond reputeDarren has a reputation beyond repute

Quote:
Originally Posted by Betty Boop View Post
Hello Everyone,

I am the girlfriend with the Php Problem. I have tried using the JSON, I think I need to elaborate on it as it isn't doing anything different at the moment.

Thanks.
UH OH! my one place of freedom now gone

Last edited by Darren; 10-01-2010 at 05:07:23 PM.
Darren is offline  
Old 10-01-2010, 05:04:59 PM     #8 (permalink)

 
davedevelopment's Avatar
 
Join Date: May 2009
Location: Brough, East Yorks
Posts: 988
davedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond repute

Here's an example:

PHP Code:
$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);

// prints <a href="http://www.imdb.com/title/tt0120689/" title="The Green Mile">The Green Mile (1999)</a> 
davedevelopment is online now  
Old 10-01-2010, 05:11:18 PM     #9 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

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.
Betty Boop is offline  
Old 10-01-2010, 05:55:22 PM     #10 (permalink)

 
accelerator's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 4,764
accelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond repute

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
accelerator is online now  
Closed Thread



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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

Domain Sponsor 2


All times are GMT. The time now is 01:24:50 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".