Jump to content

"," not working.


sepoto

Recommended Posts

Sorry guys. To me this code couldn't be more cut and dry yet the comma is NEVER found! What do I do in a situation like this? EasyPHP on Windows7.<?php$fh = fopen("guestbook.txt",'r');$book = fread($fh,filesize("guestbook.txt"));fclose($fh);$cnt = strlen($book); for($int =0; $int<$cnt; ++$int) { if($book[$int]==',') echo ","; }?>Thanks!

Link to comment
Share on other sites

Basic debugging, just print everything out. Print out $book to verify it is what you think it is, print $cnt, print $book[$int], etc. If $book[$cnt] was a comma, it would output a comma, right? So, if it doesn't output a comma, then $book[$int] is never a comma, because if it were, then it would print. So, print out the values of everything to verify they are what you think they are.

Link to comment
Share on other sites

Basic debugging, just print everything out. Print out $book to verify it is what you think it is, print $cnt, print $book[$int], etc. If $book[$cnt] was a comma, it would output a comma, right? So, if it doesn't output a comma, then $book[$int] is never a comma, because if it were, then it would print. So, print out the values of everything to verify they are what you think they are.
Thanks for the reply but that just isn't it. I did echo the string and clearly it contains a number of commas. I believe this to be a character encoding issue but I have not identified the problem just yet.
Link to comment
Share on other sites

Thanks for the reply but that just isn't it. I did echo the string and clearly it contains a number of commas. I believe this to be a character encoding issue but I have not identified the problem just yet.
you should follow through on JSG advice however, add echo out each interation of the loop, to verify what each character being checked is...
<?php$fh = fopen("guestbook.txt",'r');$book = fread($fh,filesize("guestbook.txt"));fclose($fh);$cnt = strlen($book);echo $book;echo $count;for($int =0; $int<$cnt; ++$int){  echo $book[int];  if($book[$int]==',')	echo ",";};?>

Link to comment
Share on other sites

It may be better to output something other than a comma:

<?php$fh = fopen("guestbook.txt",'r');$book = fread($fh,filesize("guestbook.txt"));fclose($fh);$cnt = strlen($book);echo $book;echo $cnt;for($int =0; $int<$cnt; ++$int){  echo $book[$int];  if($book[$int]==',')	echo "COMMA";};?>

Link to comment
Share on other sites

It may be better to output something other than a comma:
<?php$fh = fopen("guestbook.txt",'r');$book = fread($fh,filesize("guestbook.txt"));fclose($fh);$cnt = strlen($book);echo $book;echo $cnt;for($int =0; $int<$cnt; ++$int){  echo $book[$int];  if($book[$int]==',')	echo "COMMA";};?>

ah yes, I see that benefit now
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...