Hi,
I'm trying to work out a better way to extract a URL from a { } hash value dumped in a mySQL table. The value held looks like so:
The current PHP that handles this did work, but for some reason its stopped now - and I'm not sure why. Here it is:
Can anyone think of a better way to do this? Maybe a regex of some kind? I'm more of a Perl person, so if you could advise me on the formatting, I should be able to get the regex working (basically just needs to select the URL from after the `Image1_thumbnail` part)
TIA!
Andy
I'm trying to work out a better way to extract a URL from a { } hash value dumped in a mySQL table. The value held looks like so:
Code:
{
'Image1' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/4/384654-accueil.jpg',[/URL]
'Image1_large' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/5/384665-large_accueil.jpg',[/URL]
'Image1_largest' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/2/384662-largest_accueil.jpg',[/URL]
'Image1_medium' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/6/384656-medium_accueil.jpg',[/URL]
'Image1_thumbnail' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/1/384661-thumbnail_accueil.jpg',[/URL]
'Image2' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/5/384655-untitled.png',[/URL]
'Image2_large' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/3/384653-large_untitled.png',[/URL]
'Image2_largest' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/9/384669-largest_untitled.png',[/URL]
'Image2_medium' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/9/384659-medium_untitled.png',[/URL]
'Image2_thumbnail' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/7/384667-thumbnail_untitled.png',[/URL]
'Image3' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/0/384660-la_laiterie.jpg',[/URL]
'Image3_large' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/2/384652-large_la_laiterie.jpg',[/URL]
'Image3_largest' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/4/384664-largest_la_laiterie.jpg',[/URL]
'Image3_medium' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/0/384670-medium_la_laiterie.jpg',[/URL]
'Image3_thumbnail' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/7/384657-thumbnail_la_laiterie.jpg',[/URL]
'Image4' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/1/384651-ch5.jpg',[/URL]
'Image4_large' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/8/384658-large_ch5.jpg',[/URL]
'Image4_largest' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/6/384666-largest_ch5.jpg',[/URL]
'Image4_medium' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/3/384663-medium_ch5.jpg',[/URL]
'Image4_thumbnail' => '[URL unfurl="true"]http://www.chambresdhotes.org/links/images/8/384668-thumbnail_ch5.jpg',[/URL]
'extra' => {
'Image1_height' => '1137',
'Image1_large_height' => '400',
'Image1_large_width' => '193',
'Image1_largest_height' => '600',
'Image1_largest_width' => '290',
'Image1_medium_height' => '300',
'Image1_medium_width' => '145',
'Image1_thumbnail_height' => '300',
'Image1_thumbnail_width' => '145',
'Image1_width' => '550',
'Image2_height' => '160',
'Image2_large_height' => '160',
'Image2_large_width' => '213',
'Image2_largest_height' => '160',
'Image2_largest_width' => '213',
'Image2_medium_height' => '160',
'Image2_medium_width' => '213',
'Image2_thumbnail_height' => '150',
'Image2_thumbnail_width' => '200',
'Image2_width' => '213',
'Image3_height' => '319',
'Image3_large_height' => '220',
'Image3_large_width' => '399',
'Image3_largest_height' => '319',
'Image3_largest_width' => '578',
'Image3_medium_height' => '165',
'Image3_medium_width' => '300',
'Image3_thumbnail_height' => '110',
'Image3_thumbnail_width' => '199',
'Image3_width' => '578',
'Image4_height' => '730',
'Image4_large_height' => '400',
'Image4_large_width' => '346',
'Image4_largest_height' => '600',
'Image4_largest_width' => '520',
'Image4_medium_height' => '300',
'Image4_medium_width' => '260',
'Image4_thumbnail_height' => '230',
'Image4_thumbnail_width' => '200',
'Image4_width' => '633'
},
'unchanged' => {
'Image1' => 'accueil.jpg',
'Image1_large' => 'large_accueil.jpg',
'Image2' => 'untitled.png',
'Image2_large' => 'large_untitled.bmp',
'Image3' => 'la_laiterie.jpg',
'Image3_large' => 'large_la_laiterie.jpg',
'Image4' => 'ch5.jpg',
'Image4_large' => 'large_ch5.jpg'
}
};
The current PHP that handles this did work, but for some reason its stopped now - and I'm not sure why. Here it is:
Code:
if (strpos(strtolower($slideshowcache),".jpg",strpos(strtolower($slideshowcache),'thumbnail_'))) $imagelinkendpos = strpos(strtolower($slideshowcache),".jpg",strpos(strtolower($slideshowcache),'thumbnail_'))+3;
if (strpos(strtolower($slideshowcache),".jpeg",strpos(strtolower($slideshowcache),'thumbnail_'))) $imagelinkendpos = strpos(strtolower($slideshowcache),".jpeg",strpos(strtolower($slideshowcache),'thumbnail_'))+3;
if (strpos(strtolower($slideshowcache),".gif",strpos(strtolower($slideshowcache),'thumbnail_'))) $imagelinkendpos = strpos(strtolower($slideshowcache),".gif",strpos(strtolower($slideshowcache),'thumbnail_'))+3;
if (strpos(strtolower($slideshowcache),".png",strpos(strtolower($slideshowcache),'thumbnail_'))) $imagelinkendpos = strpos(strtolower($slideshowcache),".png",strpos(strtolower($slideshowcache),'thumbnail_'))+3;
if (strpos(strtolower($slideshowcache),".bmp",strpos(strtolower($slideshowcache),'thumbnail_'))) $imagelinkendpos = strpos(strtolower($slideshowcache),".bmp",strpos(strtolower($slideshowcache),'thumbnail_'))+3;
fwrite($detailsfile," ending at ".$imagelinkendpos);
$slideshow = $slideshowcache;
$linkstart = 0;
while (strpos(strtolower($slideshow),"http:",$linkstart+5)){
$prevpos = $linkstart;
$linkstart = strpos(strtolower($slideshow),"http:",$linkstart+5);
if ($linkstart > $imagelinkendpos){
$linkstart = $prevpos;
$slideshow = str_repeat("a",$linkstart+10);
}
}
$imagelink = substr($slideshowcache,$linkstart,($imagelinkendpos-$linkstart+1));
fwrite($detailsfile,$imagelink);
Can anyone think of a better way to do this? Maybe a regex of some kind? I'm more of a Perl person, so if you could advise me on the formatting, I should be able to get the regex working (basically just needs to select the URL from after the `Image1_thumbnail` part)
TIA!
Andy