473,382 Members | 1,464 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,382 software developers and data experts.

Newline doesn't work always....??

The \n I write out to an open file does not work
the second time:

$xmlstr = "<?xml version=\"1.0\"\x3F>\n";
$songstr = "<songs>\n";

fwrite($handle, "$xmlstr"); //after this I got a new line
fwrite($handle, "$songstr"); //but not after this

$lines = file("./clips/$file_name");
foreach ($lines as $line_num => $line) {

fwrite($handle, " <song path=\"$line"); //$line is from
another file containing path and song text.
}

The output:

<?xml version="1.0"?>
<songs> <song path="http://209.245.59.124/song.mp3

Should be:

<?xml version="1.0"?>
<songs>
<song path="http://209.245.59.124/song.mp3
What do I do wrong??

Ralph
Jan 29 '06 #1
4 3896
Ralph Höglund wrote:
The \n I write out to an open file does not work
the second time:

$xmlstr = "<?xml version=\"1.0\"\x3F>\n";
$songstr = "<songs>\n";

fwrite($handle, "$xmlstr"); //after this I got a new line
fwrite($handle, "$songstr"); //but not after this
I don't know what is the solution to your problem, but you certainly do
not have to surround variables with quotes to write them to a file. This
would do:

fwrite($handle, $xmlstr);

If you want to insert a variable in a string then you need quotes:

fwrite($handle, "The contents of this string is $xmlstr");
$lines = file("./clips/$file_name");
foreach ($lines as $line_num => $line) {

fwrite($handle, " <song path=\"$line"); //$line is from another file
containing path and song text.


And I guess this line should read

fwrite($handle, " <song path=\"$line\">");

Jonathan

Jan 29 '06 #2
Ralph Höglund wrote:
The \n I write out to an open file does not work
the second time:

$xmlstr = "<?xml version=\"1.0\"\x3F>\n";
$songstr = "<songs>\n";

fwrite($handle, "$xmlstr"); //after this I got a new line
fwrite($handle, "$songstr"); //but not after this

<snip>

in what mode did you fopen the file?

/* open $filename in text mode */
$handle = fopen($filename, "wt");

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 29 '06 #3
Pedro Graca skrev:
Ralph Höglund wrote:
The \n I write out to an open file does not work
the second time:

$xmlstr = "<?xml version=\"1.0\"\x3F>\n";
$songstr = "<songs>\n";

fwrite($handle, "$xmlstr"); //after this I got a new line
fwrite($handle, "$songstr"); //but not after this

Thanks all, I found out that I needed to use both \r and \n to
get it working. I am slowly getting the grasp of php programming now.

<snip>

in what mode did you fopen the file?

/* open $filename in text mode */
$handle = fopen($filename, "wt");

Well, I opened it with "w", no problem with that.

I had also to trim the lines from my m3u-file to get rid of
return and newline chars.

foreach ($lines as $line_num => $line) {
echo $line;
$line = trim($line);
fwrite($handle, " <song path=\"$line\"\r\n");
}
fclose($handle);

Now I have left the extraction of the song title to be invoked
into the end of lines as title = "song.mp3">

Will be back when (if) new problems arise.

Ralph in Sweden
Jan 29 '06 #4
*** Ralph Höglund escribió/wrote (Sun, 29 Jan 2006 22:52:50 GMT):
Thanks all, I found out that I needed to use both \r and \n to
get it working. I am slowly getting the grasp of php programming now.


Well, that's a different issue. You need to use \r\n is you want to open
the file with Windows notepad, because that's the line ending convention in
windows. Linux/Unix use \n and (if I recall correctly, Mac computers use
\r). But you can always read the file correctly if you use a proper text
editor.

--
-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--
Jan 31 '06 #5

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

Similar topics

16
by: John Smith | last post by:
Hi all Why doesn't this seem to work? void stripnl(char *sz) { char *nl; nl = strchr(sz, '\n'); if (nl) {
4
by: Till Crueger | last post by:
Hi, I have a little problem with the following code: #include <stdio.h> int main(void) { char input='\0'; while(input!='q') { printf("Menu\n"); fflush(stdout);
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
4
by: Peter Kirk | last post by:
Hi I would like to ask a little bit about the value Environment.Newline: what is it and what is the point of it? Ok, I can see in the docs that it represents "newline" for the current platform -...
16
by: infernon | last post by:
Hello Everyone, I am running PHP for Apache on a Windows XP machine. When I attempt to use \n in my code to generate a newline, it does not work. I've also see the other posts about using \r...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
11
by: Michael | last post by:
I'm new to PHP. I see that PHP supports the C printf function, and I've seen examples like printf("Hello world!\n"); however the newline character \n doesn't work - i.e., it does not generate an...
6
by: versus | last post by:
Hi I have a table column that has multiple lines (\r\n) and html tags in it. I want to display it in a div and label that html tags can be seen and newlines should work. If i use div.innerHTML...
4
by: Florian Lindner | last post by:
Hello, I have a piece of code like that: for row in resultSet: logs += "/home/%s/%s/log/access.log \n" % (row, row) logs += "/home/%s/%s/log/error.log \n" % (row, row) # <-- Now I want to...
1
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.