/    Sign up×
Community /Pin to ProfileBookmark

get URL parse and reformat

Hey all,
I have the need to grab the HREF value from a link to an image, parse it, append it with “[COLOR=”DarkRed”]-144×127[/COLOR]” and reassemble it
for use as the src for a dynamic thumbnail. I have the following worked out, but… surely there’s a better way?

[code=php]
// ex. HREF
// url http://www.alternamart.org/demox/wp-content/uploads/2011/08/honeybake_baking_set.jpg
if(jQuery(‘div.pods_field_photo>div>a’).first().length>0)
{ photo_url = jQuery(‘.pods_field_photo>div>a’).first().attr(‘href’);
photo_name = basename(photo_url);
path = photo_url.split(photo_name);
splt_thmb = photo_name.split(‘.’)
src = path[0]+splt_thmb[0]+’-144×127.’+splt_thmb[1];
} else src = jQuery(‘#no_image’).val();
jQuery(‘#pre_load_src’).val(src);
jQuery(‘.pre_load’).attr(‘src’,src);

function basename(path) {
return path.replace(/\/g,’/’).replace( /.*//, ” );
}

// src = http://www.alternamart.org/demox/wp-content/uploads/2011/08/honeybake_baking_set-114×127.jpg
[/code]

Of course it would be a lot easier to split on the file extension, but I won’t necessarily know whether the file is a GIF, PNG, JPEG… so…?
Any thoughts?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@WallabyKidauthorAug 25.2011 — [code=php]
// url http://www.alternamart.org/demox/wp-content/uploads/2011/08/honeybake_baking_set.jpg
if(jQuery('div.pods_field_photo>div>a').first().length>0)
{ photo_url = jQuery('.pods_field_photo>div>a').first().attr('href');
ext = photo_url.substr( (photo_url.lastIndexOf('.')));
src = photo_url.split(ext)[0]+'-144x127'+ext;
} else src = jQuery('#no_image').val();
jQuery('#pre_load_src').val(src);
jQuery('.pre_load').attr('src',src);

// src = http://www.alternamart.org/demox/wp-content/uploads/2011/08/honeybake_baking_set-114x127.jpg
[/code]
×

Success!

Help @WallabyKid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...