473,587 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3909
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
4323
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
9489
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
3433
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
4468
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 - I assume that it is a runtime property, and not compile time? But won't it always be the same anyway - does dotnet run on anything other than...
16
2140
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 along with \n, but that doesn't work either. I'm sort of stuck here. Is there anything that I can do to generate a newline?
16
38598
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 into the buffer ?
11
24878
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 HTML <br>, which I would have expected - what it does is generate a newline in the html generated text, but since the browser ignores blank lines,...
6
11345
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 newlines are lost and html tags doesn't show. If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks works but html tags doesn't...
4
1979
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 avoid the newline at the last iteration and only at the second line. How to do that most elegantly with Python?
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.