Page 1 of 1
exploding problem
Posted: Sat Nov 25, 2006 3:30 pm
by a94060
Hello all,
This is the code first of all
Code: Select all
$file = file_get_contents('/.proxypass');
$handle2 = explode(" \n",$file);
print_r ($handle2);
the file proxypass contains things like
sd:6IRDxD77QXpmM
fh:KyyafHQJkt6wc
in there. When i do what i have done at the top,it still comes out as one string,i want to make it so that sd is $array[0] and fh is $array[1]. I dont mind if the : values are still there,i just want the whole string sotred,is this possible?
Posted: Sat Nov 25, 2006 3:33 pm
by nickvd
Look at the delimiter string you are using... " \n" (there's something extra in there that is messing things up)
(alternatively you can use the file() function to accomplish the same task automatically)
Posted: Sat Nov 25, 2006 3:39 pm
by a94060
Well,does the \n refer to new line or is it something else that is used to represent a newline?
Posted: Sat Nov 25, 2006 4:57 pm
by Ambush Commander
The \n is interpolated in the double-quotes into a newline. Thus, '\n' != "\n"
Posted: Sat Nov 25, 2006 5:08 pm
by a94060
oh allright,i have got another problem now. i want to write this stuff to a file. the files name is sucker.txt and i am using php4. This means that i cannot use file_put_contents,can someone show me how to do it with fread,write and close?
Posted: Sat Nov 25, 2006 5:09 pm
by Ambush Commander
Posted: Sat Nov 25, 2006 5:10 pm
by a94060
i cant use that since im on php4 like i said -.-
Posted: Sat Nov 25, 2006 5:11 pm
by Ambush Commander
Read the manual page (specifically the comments).
Posted: Sat Nov 25, 2006 5:13 pm
by a94060
ok,im doing it right now

I just reslized your from new jersey also.
Posted: Sat Nov 25, 2006 5:16 pm
by Ambush Commander
New Jersey has a lot of people, hmm?

Posted: Sat Nov 25, 2006 5:23 pm
by a94060
it sure does. I got another problem still.

When i write the file with \n as the imploder,it gives me a line of text,i want it to put each value on a diffrent line.
i have done this code :
Code: Select all
include "sql.php";
$sql = "SELECT hash FROM times WHERE time_left > 0";
$result = mysql_query($sql);
$hash = array();
$i = 0;
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$hash[$i++] = $row['hash'];
}
$test = implode('<br>', $hash);
$write = file_put_contents('/.proxypass',$test);
print_r($write);
it shows me
249682\n980358\n492570\n506748\n388483\n573195\n657630\n960587\n332444\n984991\n167011\n786220\n241823\n360768\n891647\n814833\n229773
i expect the numbers but why isnt it putting it on a newline? If i do <br> it shows the text on the screen each on a diffrent line,but when i save it,it shows the samething except with <br>. If i just do \n without '
it says something about Ascii characters.
Posted: Sat Nov 25, 2006 6:25 pm
by nickvd
a94060 wrote:i expect the numbers but why isnt it putting it on a newline? If i do <br> it shows the text on the screen each on a diffrent line,but when i save it,it shows the samething except with <br>. If i just do \n without '
it says something about Ascii characters.
RE:
Ambush Commander wrote:The \n is only interpolated as a newline only in double-quotes. Thus, '\n' != "\n"
Posted: Sat Nov 25, 2006 6:32 pm
by a94060
Once again,google is the winner.

A quick check of the word interpolaton gave me my answers,thanks all.