473,405 Members | 2,354 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,405 software developers and data experts.

Spaces in URL causes split() to not work

Ciary
247 Expert 100+
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;;;TYPE;;;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?
Apr 23 '09 #1
7 1517
Markus
6,050 Expert 4TB
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).
Apr 23 '09 #2
Ciary
247 Expert 100+
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;;;hello;;;hello;;;mydata;;;mydata

php returns:
projects/twilight/twilight.txt;;;projects/twilight/light.doc;;;pdf;;;projects/twilight/light.pdf;;;hello;;;hello;;;mydata;;;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;;;projects/new light/light.doc;;;pdf;;;projects/new light/light.pdf;;;hello;;;hello;;;mydata;;;mydata

php returns:
projects/new light/new light.txt;;;projects/new light/light.doc;;;projects/new light/light.pdf;;;mydata;;;mydata

this is what's wrong

strange thing is, in FF he does both like it should.
Apr 23 '09 #3
Markus
6,050 Expert 4TB
OK. It's how you're reading the file then. Let's have a look.

Mark.
Apr 23 '09 #4
Dormilich
8,658 Expert Mod 8TB
is, in turn, PHP fed with the right input from IE?
Apr 23 '09 #5
Ciary
247 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $file = $_GET["path"];
  3.  
  4. $id = fopen($file, "r");
  5. $data = fread($id, filesize($file));
  6. fclose($id);
  7.  
  8. echo $data;
  9. ?>
this is the code which will echo the string
Apr 23 '09 #6
Ciary
247 Expert 100+
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
Apr 23 '09 #7
Ciary
247 Expert 100+
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?path=projects/new light/new light.txt to openFile.php?path='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.
Apr 23 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
6
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
2
by: nospam | last post by:
The following split command will perform the split on one or more spaces. How can I perform the split on one or more spaces AND tabs? Or for that matter, ANY whitespace? This reads input from...
7
by: Jason | last post by:
When users fill out my text area field, there is a chance that there will be no line feeds or cariage returns or spaces and just one really long word. THIS CAUSES A MAJOR PROBLEM! What I am trying...
5
by: Christine | last post by:
I have a text file that appears to be delimited by multiple spaces. The split function will only work with one space if I am correct. Is there some way to split this file into an array without...
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
40
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory...
2
by: Beliavsky | last post by:
How can I replace multiple consecutive spaces in a file with a single character (usually a space, but maybe a comma if converting to a CSV file)? Ideally, the Python program would not compress...
4
by: koutoo | last post by:
If I have a text file that is delimited by spaces, how do I import it and get to comma delimited? Here is a row of data from the text file: 1 1 10:55:14 2 65 8.5 1.4+1.1 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.