urlencode a file with newlines ...

This is a discussion on urlencode a file with newlines ... within the PHP Language forums, part of the PHP Programming Forums category; So I can't seem to urlencode a file with newlines ... it just gives me a series of T_STRING unexpected ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2006
dbee
 
Posts: n/a
Default 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 ... ?

Reply With Quote
  #2 (permalink)  
Old 02-27-2006
dbee
 
Posts: n/a
Default Re: urlencode a file with newlines ...


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...

Reply With Quote
  #3 (permalink)  
Old 02-27-2006
dbee
 
Posts: n/a
Default Re: urlencode a file with newlines ...

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...


Reply With Quote
  #4 (permalink)  
Old 02-27-2006
dbee
 
Posts: n/a
Default Re: urlencode a file with newlines ...


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 ?

Reply With Quote
  #5 (permalink)  
Old 02-27-2006
Carl Vondrick
 
Posts: n/a
Default Re: urlencode a file with newlines ...

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?
Reply With Quote
  #6 (permalink)  
Old 02-27-2006
Iván Sánchez Ortega
 
Posts: n/a
Default Re: urlencode a file with newlines ...

-----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-----
Reply With Quote
  #7 (permalink)  
Old 02-27-2006
dbee
 
Posts: n/a
Default Re: urlencode a file with newlines ...


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
....

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:15 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0