Search code examples
phparraysparse-url

Exploding array for url


I'm developing a site for analyzing a store's data. I need the url part of my array to look like this:

array(
    'url'       => 'http://some.website.com:8080/SASStoredProcess/do?_username=user-123',
    '_password' => 'passwd',
    '_program'  => '/Utilisateurs/DARTIES3-2012/Mon dossier/analyse_dc',
    'annee'     => '2012',
    'ind'       => 'V',
    '_action'   => 'execute'
);

I currently have this and am struggling to convert it to the desired format:

array(
    'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
    'otherKey' => 'otherValue'
);

Please can somebody help me to convert the URL in the second code block to look like the first code block? Thanks in advance.


Solution

  • So this will extract the url in the form you want, as $url:

    $myArray = array(
        'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
        'otherKey' => 'otherValue'
    );
    parse_str($myArray['url']);
    echo $url;
    

    You will need to decide where it needs to go next and how you get it there.