Re: Help taking a string from a file

From: Date: Sat, 14 Jan 2006 18:26:22 +0000
Subject: Re: Help taking a string from a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-228621@lists.php.net to get a copy of this message
Lists wrote:
Hello List, I made something work, but probably in the most crappy way possible. My goal is to take just the HTML for the image and link from the Flickr badge js script. This is what I did, please help me do in a better way. I'd appreciate good sources to read to learn to strip stuff away and just get specific parts as well. I never know which of the str functions to use. <? // allow retrieval of external web source ini_set('allow_url_fopen',1); // get flickr js file $photo = file_get_contents("http://www.flickr.com/badge_code_v2.gne? count=1&display=latest&size=m&layout=h&source=user&user=91667218% 40N00"); //get rid of all the crap except for the image tags $photo = strstr($photo, '<a'); list($image, $trash) = explode("'", $photo); $image = ereg_replace("</td>","", $image); ?>
why not just do: $file = file_get_contents('http://www.flickr.com/badge_code_v2.gne?count=1&display=latest&size=m&layout=h&source=user&user=91667218%40N00'); preg_match('#<img (.*)src="(.+)"#U', $file, $r); $photo = $r[2]; ? - tul

« previous php.general (#228621) next »