Not really a CakePHP specific question. But today is your lucky day. A) 
I'm looking for any kind of excuse to not study for my physics final 
tomorrow. B) I like playing with array, regex and urls : ).

So here you go:
---------------------------------------------------------------------------------------------------------------------------------------------------------------
$vendorUrl = 
toStupidVendorUrl('http://servername.com/resorts/view/12/28/4');
debug($vendorUrl);

function toStupidVendorUrl($url)
{
    $uri = parse_url($url);
    $path = explode('/', substr($uri['path'], 1));
    $query = array();
    foreach ($path as $i => $element)
    {
        $i = ife($i == 0, null, $i);
        $query['var'.$i] = $element;
    }
    $query = http_build_query($query);
    return 
preg_replace('/^('.preg_quote($uri['scheme']).':\/\/.+\/).+$/UD', 
'\\1?'.$query, $url);
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------
(Code requires CakePHP or PHP5)

-- Felix
--------------------------
http://www.thinkingphp.org
http://www.fg-webdesign.de


Erich C. Beyrent wrote:
> I have a vendor that is doing email marketing for me.  They allow custom 
> fields to be specified in their content templates.  However, they don't 
> support full urls as a custom field, only parts of the query string.
>
> I am sending them a URL like:
>
> http://servername.com/resorts/view/12/28/4
>
> and they need me to break that into:
>
> http://servername.com/?var=resorts&var2=view&var3=12&var4=28&var5=4
>
> Any ideas how to accomplish this?
>
> -Erich-
>
>
> >
>
>   

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to