Page 1 of 1

String problem

Posted: Fri May 26, 2006 10:04 am
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);
}

?>

Posted: Fri May 26, 2006 10:28 am
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.

Posted: Sat May 27, 2006 10:04 am
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