urlencode a file with newlines ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dbee

    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('$fil e');" ; done > job_description _encoded &&
    URL_ENCODED_DES CRIPTION=`cat job_description _encoded`

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

  • dbee

    #2
    Re: urlencode a file with newlines ...


    dbee wrote:[color=blue]
    > 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('$fil e');" ; done > job_description _encoded &&
    > URL_ENCODED_DES CRIPTION=`cat job_description _encoded`
    >
    > ... this takes in a job_description file and outputs a file with alot
    > of errors in the text ... ?[/color]

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

    Comment

    • dbee

      #3
      Re: urlencode a file with newlines ...

      Now I have ...

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

      echo "$URL_ENCODED_D ESCRIPTION"

      which preserves linefeeds and spaces but loses carriage returns... I
      think I can do without apostraphes if I have to ...


      dbee wrote:[color=blue]
      > dbee wrote:[color=green]
      > > 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('$fil e');" ; done > job_description _encoded &&
      > > URL_ENCODED_DES CRIPTION=`cat job_description _encoded`
      > >
      > > ... this takes in a job_description file and outputs a file with alot
      > > of errors in the text ... ?[/color]
      >
      > 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...[/color]

      Comment

      • dbee

        #4
        Re: urlencode a file with newlines ...


        dbee wrote:[color=blue]
        > 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('$fil e');" ; done > job_description _encoded &&
        > URL_ENCODED_DES CRIPTION=`cat job_description _encoded`
        >
        > ... this takes in a job_description file and outputs a file with alot
        > of errors in the text ... ?[/color]

        So now I have this

        URL_ENCODED_DES CRIPTION="`cat job_description `"

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

        echo "$URL_ENCODED_D ESCRIPTION"

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

        Comment

        • Carl Vondrick

          #5
          Re: urlencode a file with newlines ...

          dbee wrote:[color=blue]
          > dbee wrote:[color=green]
          >> 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('$fil e');" ; done > job_description _encoded &&
          >> URL_ENCODED_DES CRIPTION=`cat job_description _encoded`
          >>
          >> ... this takes in a job_description file and outputs a file with alot
          >> of errors in the text ... ?[/color]
          >
          > So now I have this
          >
          > URL_ENCODED_DES CRIPTION="`cat job_description `"
          >
          > URL_ENCODED_DES CRIPTION=`php -r "echo
          > rawurlencode('$ URL_ENCODED_DES CRIPTION');"`
          >
          > echo "$URL_ENCODED_D ESCRIPTION"
          >
          > ... which gives me a url_encoded output with spaces and linefeeds, but
          > drops all newlines ... arrrrrrg ?
          >[/color]
          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?

          Comment

          • Iván Sánchez Ortega

            #6
            Re: urlencode a file with newlines ...

            -----BEGIN PGP SIGNED MESSAGE-----
            Hash: SHA1

            dbee wrote:
            [color=blue]
            > cat job_description | while read file ; do php -r "echo
            > urlencode('$fil e');" ; done > job_description _encoded &&
            > URL_ENCODED_DES CRIPTION=`cat job_description _encoded`[/color]

            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/O3jcQ2mg3Pc8RAk LzAJ9Mnc79BVoJ9 Kr8n0I0g3gAWhuL lgCffS8l
            DTpGz+f9budu6Cw 2x+UJ+CY=
            =j2dc
            -----END PGP SIGNATURE-----

            Comment

            • dbee

              #7
              Re: urlencode a file with newlines ...


              Iván Sánchez Ortega wrote:[color=blue]
              > -----BEGIN PGP SIGNED MESSAGE-----
              > Hash: SHA1
              >
              > dbee wrote:
              >[color=green]
              > > cat job_description | while read file ; do php -r "echo
              > > urlencode('$fil e');" ; done > job_description _encoded &&
              > > URL_ENCODED_DES CRIPTION=`cat job_description _encoded`[/color]
              >
              > 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/O3jcQ2mg3Pc8RAk LzAJ9Mnc79BVoJ9 Kr8n0I0g3gAWhuL lgCffS8l
              > DTpGz+f9budu6Cw 2x+UJ+CY=
              > =j2dc
              > -----END PGP SIGNATURE-----[/color]

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

              Comment

              Working...