Reno RDW
Reno RDW

Reputation: 11

Implode on ampersand, PHP

Can someone tell me what I am doing wrong on how to implode an array on an ampersand using PHP? I am trying to send a string in AJAX that comes from this array; and nothing I am trying is working ->

$mrq = (implode("&",$mrqa));

is yielding

macro0=A¯o1=B

However, I was expecting it to yield

macro0=A&macro1=B

Is there a way to get around this? I am using UTF-8, so that shouldn't be a problem.

Upvotes: 1

Views: 537

Answers (2)

user680786
user680786

Reputation:

Problem not in implode, problem in output, because &macr is a html entity.
Use htmlspecialchars or see output in plain text, not in html.
Also, as mentioned in comments, to build your request you can use the http_build_query function.

Upvotes: 1

Adrian B
Adrian B

Reputation: 1631

You can transform each param before put in url.

foreach($mrqa as $key => $m)
$mrqa[$key] = urlencode($m);

$mrq = implode("&",$mrqa);

Upvotes: 0

Related Questions