Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php change array format for url

I have a weird project I'm working on. I'm totally new to php so it has been a struggle so far.

I have a form that gives an array and posts it:

...
return($keywords);
}

$keywordlist = explode("\r\n", $keywordlist);
foreach($keywordlist as $keyword){
print_r(mixer(strtolower($keyword)));
}

I get this:

Array ( [0] => one [1] => two [2] => three [3] => four [4] => five [5] => six [6] => ....

But would like it to come out like this instead:

%28one%2Ctwo%2Cthree%2Cfour%2Cfive%2Csix%29

Ultimately hope to be able to attach it to the end of a url like ask.com search:

"http://www.ask.com/web?q=(put my keywords here)"

then navigate there

In theory it would be like I typed "(one,two,three,four,five,six)" into the search bar and pressed enter.

Hopefully that makes some sense.

like image 519
Colby Avatar asked Dec 02 '22 02:12

Colby


1 Answers

Something like this:

$commaSeparated = implode(',', $array);
$withParens = '(' + $commaSeparated + ')';
$urlEncoded = urlencode($withParens);
print $urlEncoded;
like image 58
Sjoerd Avatar answered Dec 03 '22 14:12

Sjoerd