Spaces in URL causes split() to not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    Spaces in URL causes split() to not work

    hi all,

    i dont know if my problem is based on javascript or PHP but i think its php. it can also be a buffer problem.

    while reading a file, i've encountered a strange problem. what i do is reading the file. the file is formatted like this:

    URL;;;URL;;;TYP E;;;URL;;;NAME; ;;NAME;;;DATA;; ;DATA

    after reading the file i'm putting it into a javascript array using string.split("; ;;")
    normally there is no problem. but when there is a space in the url's (and in the url of the filepath), there appears to be a problem. in FF there is no problem, but in IE (yep it's IE again :) ) it returns a string like this:

    URL;;;URL;;;URL ;;;DATA;;;DATA

    which was the format of the file when i first created it. but i checked and it isn't in that format anymore. stranger is, if i change the of the file without spaces it works perfect.

    can anyone tell me how i should get it working with the spaces?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Please use a meaningful title when posting.

    I doubt this is PHP related, but I have been wrong before. I cannot think why a space in the string would change the way split() would work.

    I think I'll move this to JS. Please provide the code you are using JS (and PHP).

    Comment

    • Ciary
      Recognized Expert New Member
      • Apr 2009
      • 247

      #3
      just checked, it can't be js. the php script returns a wrong string so i posted it right. still this doesnt explain why php should return a string of the old file. ill give you a practical example.

      ------------------------------------------------------------------------------------------------------------------
      if i set the file like this:
      url: projects/twilight/twilight.txt

      then it would contain something like this:
      projects/twilight/twilight.txt;;; projects/twilight/light.doc;;;pdf ;;;projects/twilight/light.pdf;;;hel lo;;;hello;;;my data;;;mydata

      php returns:
      projects/twilight/twilight.txt;;; projects/twilight/light.doc;;;pdf ;;;projects/twilight/light.pdf;;;hel lo;;;hello;;;my data;;;mydata

      this is correct
      ------------------------------------------------------------------------------------------------------------------
      if i set the file like this:
      url: projects/new light/new light.txt

      then it would contain something like this:
      projects/new light/new light.txt;;;pro jects/new light/light.doc;;;pdf ;;;projects/new light/light.pdf;;;hel lo;;;hello;;;my data;;;mydata

      php returns:
      projects/new light/new light.txt;;;pro jects/new light/light.doc;;;pro jects/new light/light.pdf;;;myd ata;;;mydata

      this is what's wrong

      strange thing is, in FF he does both like it should.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        OK. It's how you're reading the file then. Let's have a look.

        Mark.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          is, in turn, PHP fed with the right input from IE?

          Comment

          • Ciary
            Recognized Expert New Member
            • Apr 2009
            • 247

            #6
            Code:
            <?php
            $file = $_GET["path"];
            
            $id = fopen($file, "r");
            $data = fread($id, filesize($file));
            fclose($id);
            
            echo $data;
            ?>
            this is the code which will echo the string

            Comment

            • Ciary
              Recognized Expert New Member
              • Apr 2009
              • 247

              #7
              ok doesnt seems to be a PHP problem, but an AJAX problem. srr to doubt about you marcus :(

              if i manually open the page openFile.php it opens the right string. doesnt explain why AJAX doesnt though. the php is correct so this thread can be relocated to the javascript forum

              Comment

              • Ciary
                Recognized Expert New Member
                • Apr 2009
                • 247

                #8
                ok, seems like AJAX saves the last given answer to answer when an error occurs. when i did something terribly wrong on my phppage it still returned the same string so.

                and i've fixed the problem. i changed the path from: openFile.php?pa th=projects/new light/new light.txt to openFile.php?pa th='projects/new light/new light.txt' and then replaced the "\'" with "" in php. that fixed it srr for the inconvenience guys and tnx for the help.

                Comment

                Working...