PDA

Click to See Complete Forum and Search --> : Use enter?


|2eM!x
Jul 24th, 2005, 12:10 AM
Id like to explode() by enter..but im not sure how

can i use chr() in php?

nkad
Jul 24th, 2005, 01:16 AM
yes, chr() is a php function. It takes an ascii code and converts it to a character.

|2eM!x
Jul 24th, 2005, 01:25 AM
so for enter id use it like this?
$entry = explode(chr("13"),$contents)

or what?

|2eM!x
Jul 24th, 2005, 02:30 AM
and would this script work:
<html>
<form>
<body>
<php?
$ip = $_SERVER['REMOTE_ADDR'];
$handle = fopen("IPTimes.txt" "r+") or die("Err1");
$contents = @fread($handle,filesize("IPTimes.txt")) or die("Err2");
If(Strpos($contents,$ip)===False){
fwrite($handle,$contents.chr(13+10).":".$ip."1");
$NumVisits = 1
}Else{
$entry = explode(chr(13 + 10),$contents);
$Number = 0;
foreach($entry as $x){
$Number2 = explode($entry['$Number'];
$Number2['1']++;
$NumVisits = $Number2['1'];
$Number++;
}
}
Echo $ip."</br>".$NumVisits
?>
</body>
</form>
</html>

nkad
Jul 24th, 2005, 02:38 AM
i think $entry = explode(chr(13 + 10),$contents);

should be $entry = explode(chr(13) . chr(10),$contents);

the rest of your code looks good

|2eM!x
Jul 24th, 2005, 03:23 AM
if thats all...that sure would be a first :wave:

visualAd
Jul 24th, 2005, 03:28 AM
In PHP you can use the escape sequence \r\n for a carridge return and linefeed:

$entry = explode("\r\n",$contents);

|2eM!x
Jul 24th, 2005, 11:48 AM
thanks guys. On my echo statement, im getting this:

".$NumVisits."Visits" ?>

Instead it should be like
127.0.0.1 1 Visits

What did i do wrong?

|2eM!x
Jul 24th, 2005, 02:13 PM
wow i figured it out
<php?
<?php
:bigyello:

But i continue to get errors.
<html>
<form>
<body>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$handle = fopen("IPTimes.txt", "r+") or die("Err1");
$contents = @fread($handle,filesize("IPTimes.txt")) or die("Err2");
If(Strpos($contents,$ip)===False){
fwrite($handle,$contents."\r\n".":".$ip."1");
$NumVisits = 1;
}Else{
$entry = explode("\r\n",$contents);
$Number = 0;
foreach($entry as $x){
If(strpos($entry['$Number'],$ip)){
$Number2 = explode(":",$entry['$Number'];
$Number2['1']++;
$NumVisits = $Number2['1'];
}
$Number++;
}
}
Echo "$ip </br> $NumVisits Visits"
fclose($handle)
?>
</body>
</form>
</html>

$Number2 = explode(":",$entry['$Number'];

visualAd
Jul 24th, 2005, 04:18 PM
This is an error you make a lot, you need to ensure you close your brackets for the explode function.

|2eM!x
Jul 24th, 2005, 06:17 PM
Man. Im getting the eclipse IDE right now to fix that. Thanks