Help With Troubleshooting?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
is_blank
Forum Commoner
Posts: 36
Joined: Sat Jun 25, 2005 6:05 pm
Location: Tennessee, USA

Help With Troubleshooting?

Post by is_blank »

I hope this isn't a bother, and forgive my kludgy code; I'm just starting out! I had a script that was working fine yesterday; now it doesn't. Here's the snippet that's broken:

Code: Select all

$source_url = &quote;http://en.wikipedia.org/wiki/Wikipedia:POTD/&quote;.date(&quote;F_j%2C_Y&quote;);
$source = @file_get_contents($source_url);
$bits = explode(&quote;<!-- start content -->&quote;,$source);

//Locate the picture
$process_pic = preg_match('/<a href=&quote;\/wiki\/Image:(.*?<\/a>)/si',$bitsї1],$pic_chunk);
$process_pic = preg_match('/<img src=(.*?)\/>/si',$pic_chunkї0],$pic);
$process_pic = preg_match('/http:(.*?)\.jpg/si',$picї0],$pic_url);

//*** Test stuff ***
$break = &quote;\n\n<br/><br/>&quote;;
echo $pic_urlї0];
echo $break;

//This doesn't work --
echo('<img src=&quote;'.$pic_urlї0].'&quote;/>');
echo $break;

//But this does --
echo('<img src=&quote;http://upload.wikimedia.org/wikipedia/en/c/c2/Nat-gall-lond-tr-sq.jpg&quote;/>');

//This comes up empty --
if (!$handle = fopen($pic_urlї0], 'b')) {
         echo &quote;Cannot open file!&quote;;
         echo &quote;\n\n&quote;;
   } else {
   		echo &quote;Thar she blows!&quote;;
   		fclose($handle);
}

//But this catches the image --
if (!$handle = fopen('http://upload.wikimedia.org/wikipedia/en/c/c2/Nat-gall-lond-tr-sq.jpg', 'b')) {
         echo &quote;Cannot open file!&quote;;
         echo $break;
   } else {
   		echo &quote;Thar she blows!&quote;;
   		fclose($handle);
}
I assume there's something wrong with the way I'm generating $pic_url -- it seems like it's trying to access http://upload.wikimedia.org/wikipedia/e ... tr-sq.jpg/, and that final "/" is tripping it up, but I have no idea where it might be coming from (echo $pic_url[0]; seems to show the proper location...), and therefore I'm not sure how to strip it out.

Can anyone help? Thanks!!
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Try:

Code: Select all

echo &quote;<img src=\&quote;&quote; . $pic_urlї0] . &quote;\&quote;/>&quote;;
User avatar
is_blank
Forum Commoner
Posts: 36
Joined: Sat Jun 25, 2005 6:05 pm
Location: Tennessee, USA

Post by is_blank »

Rrgh. I'm an idiot. Thanks for the help, Crashin; seeing the two next to each other (which I should have seen before) led me to notice that the $image_url[0] string was suspiciously longer then the URL I was hard-coding in. Removing 'thumb/' from $image_url[0] sends it to the proper directory!

Sorry, I guess my brain was blurry. :(
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Sure thing! Glad you got it to go! :)
Post Reply