Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to extract string?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
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:

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
 
Ok, I just had a play around with it in Perl - and this is how I would do the regex:

Code:
my $image_url;
$test =~ m/\Q`Image1_thumbnail` : `\E(.*)\`/ and $image_url = $1;
print "Image URL: $image_url \n";

..which gives:

Code:
C:\Users\Andy>perl test.pl
Image URL: [URL unfurl="true"]http://www.chambresdhotes.org/links/images/0/91970-thumbnail_147-les-salles_1.jpg[/URL]

So all I need to do now, is work out how to convert that into PHP :)

Cheers

Andy
 
Ok cool, I did some digging and this is what I came up with (and it works =))


Code:
$check_image_count = preg_match('/\`Image1_thumbnail\` : \`(.*)\`/', $slideshowcache, $match);
if ($check_image_count === FALSE) 
    $imagelink = "no image";
else 
    $imagelink = $match[1];

Just in case anyone else comes across the same issue in the future

Cheers

Andy
 
an alternative way, without using regex (which are computationally slow), might be to unhash the hash into an array.

in general i would advise not storing data like that. if you want to store a hash store the actual php array in serialised fashion
Code:
[b][COLOR=#000000 ]serialize[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$array[/color][COLOR=#990000 ])[/color]
.

this code should unhash your array. beware - because it uses eval() it could be used for mischief if the underlying stored data is not trusted.

Code:
[COLOR=#990000 ]<?php[/color]
[COLOR=#009900 ]$string[/color] [COLOR=#990000 ]=[/color] [COLOR=#990000 ]<<<[/color]STR
[COLOR=#FF0000 ]{[/color]
[tab][COLOR=#FF0000 ]'Image1'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/4/384654-accueil.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image1_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/5/384665-large_accueil.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image1_largest'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/2/384662-largest_accueil.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image1_medium'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/6/384656-medium_accueil.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image1_thumbnail'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/1/384661-thumbnail_accueil.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image2'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/5/384655-untitled.png'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image2_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/3/384653-large_untitled.png'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image2_largest'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/9/384669-largest_untitled.png'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image2_medium'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/9/384659-medium_untitled.png'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image2_thumbnail'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/7/384667-thumbnail_untitled.png'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image3'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/0/384660-la_laiterie.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image3_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/2/384652-large_la_laiterie.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image3_largest'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/4/384664-largest_la_laiterie.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image3_medium'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/0/384670-medium_la_laiterie.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image3_thumbnail'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/7/384657-thumbnail_la_laiterie.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image4'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/1/384651-ch5.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image4_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/8/384658-large_ch5.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image4_largest'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/6/384666-largest_ch5.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image4_medium'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/3/384663-medium_ch5.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'Image4_thumbnail'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'[URL unfurl="true"]http://www.chambresdhotes.org/links/images/8/384668-thumbnail_ch5.jpg'[/URL][/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'extra'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'1137'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_large_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'400'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_large_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'193'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_largest_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'600'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_largest_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'290'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_medium_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'300'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_medium_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'145'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_thumbnail_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'300'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_thumbnail_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'145'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'550'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'160'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_large_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'160'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_large_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'213'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_largest_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'160'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_largest_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'213'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_medium_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'160'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_medium_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'213'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_thumbnail_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'150'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_thumbnail_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'200'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'213'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'319'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_large_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'220'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_large_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'399'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_largest_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'319'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_largest_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'578'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_medium_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'165'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_medium_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'300'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_thumbnail_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'110'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_thumbnail_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'199'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'578'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'730'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_large_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'400'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_large_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'346'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_largest_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'600'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_largest_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'520'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_medium_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'300'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_medium_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'260'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_thumbnail_height'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'230'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_thumbnail_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'200'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_width'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'633'[/color]
[tab][COLOR=#FF0000 ]}[/color][COLOR=#990000 ],[/color]
[tab][COLOR=#FF0000 ]'unchanged'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#FF0000 ]'Image1'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'accueil.jpg'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image1_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'large_accueil.jpg'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'untitled.png'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image2_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'large_untitled.bmp'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'la_laiterie.jpg'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image3_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'large_la_laiterie.jpg'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'ch5.jpg'[/color][COLOR=#990000 ],[/color]
[tab][tab][COLOR=#FF0000 ]'Image4_large'[/color] [COLOR=#990000 ]=>[/color] [COLOR=#FF0000 ]'large_ch5.jpg'[/color]
[tab][COLOR=#FF0000 ]}[/color]
[COLOR=#FF0000 ]}[/color][COLOR=#990000 ];[/color]
STR[COLOR=#990000 ];[/color]
[b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]hash2array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$hash[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][COLOR=#009900 ]$hash[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]str_replace[/color][/b][COLOR=#990000 ]([/color][tab][b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'{'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'}'[/color][COLOR=#990000 ]),[/color] 
[tab][tab][tab][tab][tab][tab][tab][b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'array('[/color][COLOR=#990000 ],[/color][COLOR=#FF0000 ]')'[/color][COLOR=#990000 ]),[/color] 
[tab][tab][tab][tab][tab][tab][tab][COLOR=#009900 ]$hash[/color][COLOR=#990000 ]);[/color]
[tab][b][COLOR=#0000FF ]return[/color][/b] [b][COLOR=#0000FF ]eval[/color][/b] [COLOR=#990000 ]([/color][COLOR=#FF0000 ]'return '[/color] [COLOR=#990000 ].[/color] [COLOR=#009900 ]$hash[/color][COLOR=#990000 ]);[/color][tab][tab][tab][tab][tab][tab][tab]
[COLOR=#FF0000 ]}[/color]
[b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#FF0000 ]'<pre>'[/color][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$array[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]hash2array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$string[/color][COLOR=#990000 ]);[/color]
[b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#FF0000 ]'image 1 thumbnail is '[/color] [COLOR=#990000 ].[/color] [COLOR=#009900 ]$array[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'Image1_thumbnail'[/color][COLOR=#990000 ]];[/color]
 
Hi,

Thanks. The old code was done by a previous developer, and as I explain, PHP isn't my strong point =) (I used to dabble in it 10 or so years ago, but nothing too advanced).

This map function I will be replacing into a static Perl/MySQL map at some point in the future (to comply with the rest of the site). Currently it uses an IFRAME and dynamic PHP script, which are both notoriously slow with large numbers of page views.

Thanks for the reply though :)

Andy
 
there is no need for 'dynamic php' to be slow. the majority of web sites (including some of the heaviest traffic sites in the world - eg facebook ) use php.

I would not have approached the image and slideshow management of your gite site in the manner that is suggested by the data map. most solutions to this business problem involve the image data being stored in mysql table columns. without seeing the rest of your code, I cannot comment which would be most efficient, but I suspect that the 'normal' way would take the biscuit - particularly because the keys would not be hardcoded and could therefore be extended beyond 'n' images.

Equally, I would not create all the different size images at once but use a script to retrieve and image and image size and pass the information via a cacheing (imageserver) script.

if your php site is not working as quickly as you would like then perhaps optimisation would be a better strategy than simply migrating the entire site to a new language. An experienced php coder should spot the sub-optimal code relatively easily but for those less used to the language there are a number of articles on and around the subject.

If you are convinced that there is no further optimisation that can be done (effectively) then you should look at html caching, opcode cache extensions or perhaps migrate to hiphop (which I have found effective) or hphpi (which i have not yet experimented with but looks promising) before considering a hardware upgrade.
 
Hi,

Thanks for the reply. Originally the site was in Perl, and due to the lack of knowledge by previous developers, they did parts of it in PHP (based on stuff they found on google). The overall system running on the site is actually Perl ... and I've already converted this kinda map stuff over on another of a similar site (so the hard work has already been done). Seems silly having both PHP + Perl on the same site, when I have the know how of Perl (and ability to fix any bugs that arise, just like the one in this post) it seems silly to even be using any PHP on the site (not that I don't like PHP ... I just never got on with it, and much prefer Perl and MySQL as my choice of language =))

Regarding the hash stuff (with the images) that is actually created at compilation time when the listing is added (the field is a "text cache", so supposidly quicker access). I'm not a fan of this method - and when I changed the other site over to use Perl, I simply access the value directly in the database (which is done at compilation time, so it very quick)

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top