473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

urlencode a file with newlines ...

So I can't seem to urlencode a file with newlines ... it just gives me
a series of T_STRING unexpected parse errors...

cat job_description | while read file ; do php -r "echo
urlencode('$file');" ; done > job_description_encoded &&
URL_ENCODED_DESCRIPTION=`cat job_description_encoded`

.... this takes in a job_description file and outputs a file with alot
of errors in the text ... ?

Feb 27 '06 #1
6 2596

dbee wrote:
So I can't seem to urlencode a file with newlines ... it just gives me
a series of T_STRING unexpected parse errors...

cat job_description | while read file ; do php -r "echo
urlencode('$file');" ; done > job_description_encoded &&
URL_ENCODED_DESCRIPTION=`cat job_description_encoded`

... this takes in a job_description file and outputs a file with alot
of errors in the text ... ?


oops ... it seems that I misunderstood the problem. The T_STRING error
is caused by an apostraphe in the text. I looked on php.net and it
seems to suggest that I should use rawurlencode(), but that doesn't
make any difference - I still get the error.

Also, I lose all my newlines ... I'm playing around with the cat
job_description function...

Feb 27 '06 #2
Now I have ...

URL_ENCODED_DESCRIPTION=`php -r "echo
rawurlencode('$URL_ENCODED_DESCRIPTION');"`

echo "$URL_ENCODED_DESCRIPTION"

which preserves linefeeds and spaces but loses carriage returns... I
think I can do without apostraphes if I have to ...
dbee wrote:
dbee wrote:
So I can't seem to urlencode a file with newlines ... it just gives me
a series of T_STRING unexpected parse errors...

cat job_description | while read file ; do php -r "echo
urlencode('$file');" ; done > job_description_encoded &&
URL_ENCODED_DESCRIPTION=`cat job_description_encoded`

... this takes in a job_description file and outputs a file with alot
of errors in the text ... ?


oops ... it seems that I misunderstood the problem. The T_STRING error
is caused by an apostraphe in the text. I looked on php.net and it
seems to suggest that I should use rawurlencode(), but that doesn't
make any difference - I still get the error.

Also, I lose all my newlines ... I'm playing around with the cat
job_description function...


Feb 27 '06 #3

dbee wrote:
So I can't seem to urlencode a file with newlines ... it just gives me
a series of T_STRING unexpected parse errors...

cat job_description | while read file ; do php -r "echo
urlencode('$file');" ; done > job_description_encoded &&
URL_ENCODED_DESCRIPTION=`cat job_description_encoded`

... this takes in a job_description file and outputs a file with alot
of errors in the text ... ?


So now I have this

URL_ENCODED_DESCRIPTION="`cat job_description`"

URL_ENCODED_DESCRIPTION=`php -r "echo
rawurlencode('$URL_ENCODED_DESCRIPTION');"`

echo "$URL_ENCODED_DESCRIPTION"

.... which gives me a url_encoded output with spaces and linefeeds, but
drops all newlines ... arrrrrrg ?

Feb 27 '06 #4
dbee wrote:
dbee wrote:
So I can't seem to urlencode a file with newlines ... it just gives me
a series of T_STRING unexpected parse errors...

cat job_description | while read file ; do php -r "echo
urlencode('$file');" ; done > job_description_encoded &&
URL_ENCODED_DESCRIPTION=`cat job_description_encoded`

... this takes in a job_description file and outputs a file with alot
of errors in the text ... ?


So now I have this

URL_ENCODED_DESCRIPTION="`cat job_description`"

URL_ENCODED_DESCRIPTION=`php -r "echo
rawurlencode('$URL_ENCODED_DESCRIPTION');"`

echo "$URL_ENCODED_DESCRIPTION"

... which gives me a url_encoded output with spaces and linefeeds, but
drops all newlines ... arrrrrrg ?

I do not think that newlines are supported. urlencode and rawurlencode
generate strings for being passed in URLs. Perhaps you should just do
your own escaping?
Feb 27 '06 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

dbee wrote:
cat job_description | while read file ; do php -r "echo
urlencode('$file');" ; done > job_description_encoded &&
URL_ENCODED_DESCRIPTION=`cat job_description_encoded`


PHP syntax is C-like, not Bash-like...

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Muy pronto en la vida es demasiado tarde.- Marguerite Durás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEAr/O3jcQ2mg3Pc8RAkLzAJ9Mnc79BVoJ9Kr8n0I0g3gAWhuLlgCff S8l
DTpGz+f9budu6Cw2x+UJ+CY=
=j2dc
-----END PGP SIGNATURE-----
Feb 27 '06 #6

Iván Sánchez Ortega wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

dbee wrote:
cat job_description | while read file ; do php -r "echo
urlencode('$file');" ; done > job_description_encoded &&
URL_ENCODED_DESCRIPTION=`cat job_description_encoded`


PHP syntax is C-like, not Bash-like...

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Muy pronto en la vida es demasiado tarde.- Marguerite Durás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEAr/O3jcQ2mg3Pc8RAkLzAJ9Mnc79BVoJ9Kr8n0I0g3gAWhuLlgCff S8l
DTpGz+f9budu6Cw2x+UJ+CY=
=j2dc
-----END PGP SIGNATURE-----


I've tried escaping the commas in the text, but it still doesn't work
....

Feb 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: George Hester | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;301464 Look down at the MyPage.asp example. You will see that Microsoft does this: 'Costruct the URL for the current page s = "http://"...
3
by: JP SIngh | last post by:
Hi All I have users who upload files using my application using ASPUPLOAD component. My code uploads the file to a network location and once the upload is finish I display the hyperlink using...
1
by: yawnmoth | last post by:
Any ideas as to why urlencode(addslashes(chr(0))) returns '%5C0'? It seems like it should return '%00' since that's what urlencode(chr(0)) returns. If not that, I could also see it returning...
1
by: Jim | last post by:
Hello, I'm trying to do urllib.urlencode() with unicode correctly, and I wonder if some kind person could set me straight? My understanding is that I am supposed to be able to urlencode...
4
by: Andreas Klemt | last post by:
Hello, is there a difference between System.Web.HttpUtility.UrlEncode and Server.UrlEncode ?
1
by: msn | last post by:
Invalid file name for monitoring: 'E:\inetpub\wwwroot\xxxxxxx\xxxxxxx\Server.UrlEncode("login.aspx'. File names for monitoring must have absolute paths, and no wildcards. ...
9
by: wscrsurfdude | last post by:
f = open('myfile,'r') a = f.read(5000) When I do this I get the first 634 bytes. I tried using the: f = open('myfile,'rb') option, but now there are a few 0x0D bytes extra in myfile. 0x0D =...
12
by: sleytr | last post by:
Hi, I'm trying to make a gui for a web service. Site using ± character in value of some fields. But I can't encode this character properly. >>> data = {'key':'±'} >>> urllib.urlencode(data)...
6
by: CindyH | last post by:
Hi I'm not sure whether I should send this as a new message or use the one I've been using but... I'm using vb.net 2.0 - My problem is I need to send something like this: 'dim encodedstring =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.