Page 1 of 1

GET query

Posted: Mon Jan 24, 2011 3:07 am
by aristotle
Hi, I have written a code that take the GET contents of a URL , i.e after the ? and output it as a csv file.
eg - ....../xyz.php?str=<tr><td>c1</td><td>c2</td><td>c3..........c7</tr></td>

$input = $_GET['str'];
.........
............
......


output should be as - c1,c2,c3,c4.... so on
well , i have written a code for that and it works wonderfully except that if the url contains '&' and '#'(hidden fields) in the columns , the script malfunctions coz they act as delimiters.How do I take care of that? how to fetch the contents of the URL so that the & and # dont create a problem?

Please help.. :)

Re: GET query

Posted: Mon Jan 24, 2011 9:42 am
by pickle
If you're generating the URL, use urlencode(), then urldecode() after you've converted to CSV.

Re: GET query

Posted: Tue Jan 25, 2011 12:21 am
by aristotle
NO, Im not generating the links .I am jusy typing it in the browser address bar...
it will be encoded in some button later on.. but what i want is this only... the columns I pass... in str ,
eg.- ...?str='<tr><td>c1</td><td>c2</td><td>c3</td></tr>'
are to be made into csv format..which i ve done but my problem is that if the columns i pass contain # or & , the csv line breaks before that character.
How to 'treat' the input before using $_GET[] coz $_GET[] cannot take any string that has # or & in it.

Re: GET query

Posted: Tue Jan 25, 2011 1:34 am
by cpetercarter
Your underlying problem is that http://www.mysite.com?str='<tr><td>c1</ ... 3</td></tr>' is not an allowed url. You cannot put characters like < > ' # or & into a url and expect it to work. You need to urlencode such characters first, before you put them in the url, as pickle has told you. (But you don't need to urldecode the query string when you retrieve it in the $_GET array - php does this job for you.)

More generally, I wonder why you want to transfer a set of values to csv format by trying to send an html table row in a url query string. It would be much easier to use ..?val1=c1&val2=c2&val3=c3 .... (Remember to urlencode c1, c2, c3 etc before you construct the query string). Then construct the csv string from the $_GET array, perhaps using implode()..