Saturday 15 March 2014

php - What's Laravel best way to build an external URL with query string? -



php - What's Laravel best way to build an external URL with query string? -

i'm building project laravel , need build urls query strings. url:: functions , url(), action(), etc. out of question since built internal use. urls need create external.

a similar illustration give external url static images google maps api :

https://maps.googleapis.com/maps/api/staticmap?center=new+york,ny&zoom=13&size=600x300&key=key

if have array :

<!-- language: lang-php --> array( 'center'=>'new york, ny', 'zoom'=>13, 'size'=>'600x300' )

i'm asking because it's impossible me install http_build_url / query extension , because there many functions internally. can't find best place "plug" myself.

if need reinvent wheel (which sucks, sorry hear), this.

$querystring = ''; $arraylength = count($myarray); foreach ($myarray $key => $val) { $querystring .= urlencode($key) . '=' . urlencode($val); $arraylength--; if ($arraylength) { $querystring .= '&'; } }

i'd save function, , have separate function constructing url, e.g.

function buildurl($baseuri, $params) { homecoming sprintf("%s?%s", $baseuri, buildquerystring($params)); }

but i'm not 100 % want, apologies if i'm wrong.

php url laravel

No comments:

Post a Comment