Use PHP's built in http_build_query instead of rolling your own.