Id like to explode() by enter..but im not sure how
can i use chr() in php?
Printable View
Id like to explode() by enter..but im not sure how
can i use chr() in php?
yes, chr() is a php function. It takes an ascii code and converts it to a character.
so for enter id use it like this?
$entry = explode(chr("13"),$contents)
or what?
and would this script work:
PHP Code:<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>
i thinkshould beCode:$entry = explode(chr(13 + 10),$contents);
the rest of your code looks goodCode:$entry = explode(chr(13) . chr(10),$contents);
if thats all...that sure would be a first :wave:
In PHP you can use the escape sequence \r\n for a carridge return and linefeed:
PHP Code:$entry = explode("\r\n",$contents);
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?
wow i figured it out
<php?
<?php
:bigyello:
But i continue to get errors.
$Number2 = explode(":",$entry['$Number'];PHP Code:<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>
This is an error you make a lot, you need to ensure you close your brackets for the explode function.
Man. Im getting the eclipse IDE right now to fix that. Thanks