tags:

views:

204

answers:

3

I'm sending a php script multiple urls (about 15) at once, all containing about 5 url variables. In my script, I'm parsing the chunk of urls into individual ones by splitting them with two backslashes (which i add upon before to the script), and then curling each individual url. However, when I run my script, it only accepts a url up to the "&" symbol. I'd like to have the entire chunk, so that I can split it up later in my script. What might be the best way to approach this issue?

Thanks.

An example of what happens when i send my script a url chunk:

 <?php
    /*
    $url variable being sent to script:
    http://www.test1.com?q1=a&amp;q2=b&amp;q3=c&amp;q4=d\\http://www.test2.com?r1=a&amp;r2=b&amp;r3=c&amp;r4=d\\http://www.test3.com?q1=a&amp;q2=b&amp;q3=c&amp;q4=d\\http://www.test4.com?e1=a&amp;e2=b&amp;e3=c&amp;e4=d
    */

    $url = $_GET['url'];

    echo $url; // returns http://www.test1.com?q1=a

    //later on in my script, i just need to curl each "\\" seperated url
    ?>
A: 
outis
A: 

Since you didn't url encode your url param, everything after the first & is treated as the param to the original url.

Artem Russakovskii
+1  A: 

You need to urlencode() the (data) URLs before appending them to your script's request.

Otherwise, PHP is going to to see ?listOfUrls=http://someurl.com/?someVar=SomeVal&amp; and stop right there, due to the literal "&"

If you're building the query string in PHP you could try something like:

<?PHP
//imagine $urls is an array of urls
$qs = '?urls=';
foreach($urls as $u){
    $q .= urlencode($u) .'\\';
}

I also suspect you can play with [] notation in the url so that on the other side of the GET, you get a nice clean array of URLs back, instead of having to parse on some delimiter like "\"

timdev
+1 for [] notation
Kevin Peno