String format problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

String format problems

Post by kholloi »

Hi,
I am trying to format a string to write to a file. The entries mus be seperated by newlines.
I have been messing round with syntax for a while but can't seem to get it right.

Code: Select all

$string = $fileї0]."\n" BROADCAST=.$broadcast "\n" $fileї2] "\n" $fileї3] "\n" $fileї4] "\n" $fileї5] "\n" $fileї6] "\n" $fileї7] "\n" $fileї8] "\n";
What am I doing wrong please?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

note how your string looks like with highlighting:

Code: Select all

$string = $file[0]."\n" BROADCAST=.$broadcast "\n" $file[2] "\n" $file[3] "\n" $file[4] "\n" $file[5] "\n" $file[6] "\n" $file[7] "\n" $file[8] "\n";
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

Post by kholloi »

OK. I supose that doesn't look right. Now i tried doing this:

Code: Select all

$string = '$fileї0]."\n" BROADCAST=.$broadcast "\n" $fileї2] "\n" $fileї3] "\n" $fileї4] "\n" $fileї5] "\n" $fileї6] "\n" $fileї7] "\n" $fileї8] "\n"';
but it interprets the whole string litterally? Doesn't read the "\n" tabs.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read through the manual page about strings.. http://www.php.net/manual/en/language.types.string.php
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

:shock:

You got some serious syntax issues there.

I'd so as feyd recommends.
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

Post by kholloi »

OK I RTFM'ed.

Here is the solution if anyone is interested:

Code: Select all

$string = $fileї0]."\nBROADCAST="."'$broadcast'"."\nIPADDR="."'$fileї2]'"."\n".$fileї3]."\nNETMASK="."'$fileї4]'"."\n"; 
$string .= $fileї5]."\n".$fileї6]."\n".$fileї7]."\n".$fileї8]."\n";
Post Reply