0

For example, take this code:

$ch = curl_init($resultSet['url']."?get0=get0&get1=".$get1."&get2=".$get2."&get3=".$get3);

This of course, looks very ugly, and kind of a pain in the ass to read. So my question is, would I be able to use something like this:

$allgets ="?act=phptools&host=".$host."&time=".$duration."&port=".$port;
$ch = curl_init($resultSet['url'] . $allgets);

Very simple question I suppose, but my server is undergoing maintenance, so I can't upload it and test it myself. I suppose a yes or no answer will suffice, but if you have a more efficient way of doing this, that would be even better. :)

1
  • please use urlencode() to secure your variable values Commented Apr 24, 2010 at 4:19

2 Answers 2

2

Definitely, it's just string concatenation.

You could also take a look at string variable parsing if you want it to be "less messy".

Sign up to request clarification or add additional context in comments.

Comments

0

Your example might not work depending on the value of the variables because you didn't use URL-encoding.

A better way is something like this,

$fields = array (
   'host' => $host,
   'port' => $port
);

$ch = curl_init($resultSet['url'] . '?' . http_build_query($fields));

2 Comments

I would go one further and use http_build_url as well then it would be easy to change things if the url needs changing
If url may contain query strings already, http_build_url() is definitely the way to go. However, it requires http extension, which is rarely installed on all the hosts I used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.