Hi guys, I wanted to use the cUrl function and get image url from amazon.com so this is how it going to be: 1. Search the music by artist and album's name (eg. Fall out boy - Infinity on high) 2. Grasp the album's image url from the first result 3. Insert that image url into my database. How do i do that? Or is there anywhere that i can look?
u can use preg n match to specifiy what you want then use arrays to to feed the information to your databes for other use somewhere else say if you had a div with a class of images, somthin like <DIV CLASS="amazon_imges">the image detals here< /DIV> preg_match (/<DIV CLASS="amazon_imges">(.*)< \/DIV>/,$curlvar, $output) then add $output[0] to your database look into it
<?php $artist = "Kanye West"; $album = "Graduation"; $artist = str_replace(' ','+',$artist); $album = str_replace(' ', '+', $album); $url = "http://www.amazon.com/gp/search/?search-alias=popular"; // add artist $url .= "&field-artist=" . $artist; // add title $url .= "&field-title=" . $album; // add the rest $url .= "&sort=relevancerank"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_URL, $url); $html = curl_exec($ch); // the html of the search result page is now contained within the variable $html PHP: Do something with Preg_match i dont have time to build the full function but it will be easy i hope next poster does it heres a hint: 1-1"> <img src="(.*)" class="" PHP: Can anyone help me with my situation btw: http://forums.digitalpoint.com/showthread.php?t=866142
Ok i got a problem with preg_match already when there is both quote (") and apostrophe(') in $html some search result return different html for instance, this is in the html 1-1"> <img onload="if (typeof uet =='function') { uet('af'); }" src="http://g-ecx.images-amazon.com/images/G/01/x-locale/common/transparent-pixel._V42752373_.gif" class="" Code (markup): now how do i use preg_match to match that? it has both quote and apostrophe in it therefore, i decided to use backslash \' but it didn't work if(preg_match('/1-1"> <img onload="if (typeof uet ==\'function\') { uet(\'af\'); }" src="(.*)" class=""/', $html, $d_link)) { echo "working"; } else { echo "nothing working"; } PHP: