String problem

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
Yngvefaen
Forum Newbie
Posts: 2
Joined: Wed May 24, 2006 3:48 am

String problem

Post by Yngvefaen »

I am trying to read a log file into a string and tokenize it to get a hold of the values i need. But when I try to print one or several pieces of the string it contains several question marks. Why is this happening?

Code: Select all

<?php

$filename = "c:\\apache\\Apache2\\htdocs\\test\\OISExport_Error.txt";
$handle = fopen($filename, "rb");
// $contents = fread($handle, filesize($filename));

if ($handle) {
	$i = 0;
   	while (!feof($handle)) {
       	$buffer = fgets($handle, 512);
      	$pieces = explode("	",$buffer);
	echo $pieces[0] . "<br>";
   	}
   	fclose($handle);
}

?>
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

It could be that the character set used in the file contains unreadable characters, or that the question marks represent whitespace like tabs, newlines, special printing characters etc.
Yngvefaen
Forum Newbie
Posts: 2
Joined: Wed May 24, 2006 3:48 am

Post by Yngvefaen »

You may be right, the file i'm trying to read is in unicode. I think I read somewhere that php does not support unicode directly, any way to work around this?

Edit: Ok I think it will work if I use the correct unicode characters as spacers, but how do I write unicode tab in php as opposed to the ascii \t?

Code: Select all

explode("\t",$buffer); // ascii tab
explode("?",$buffer); // unicode tab
Post Reply