Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Read special characters (, , , ....) from file


  • Please log in to reply
1 reply to this topic

#1 ThePolice

ThePolice

  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:05:37 AM

Posted 21 October 2011 - 08:54 AM

I need to read a text file (q_000190 - tab separated)in an array, and afterwards display the data in some kind of a table on a web page.
The php code I use for this purpose works fine, but there seems to be a problem regarding some special characters like , , , , .....
They either are not read correctly, or the code doesn't handle them correct.

This is a small part of the file to read:
GF 20111006 5217 Cartheft Coldare David
VO 20110902 4500 Traffic accident Ariani Genevive
GF 20110915 4788 Burglary Ariani Genevive
VO 20110826 300697 Traffic accident Cornelis Steven

As you can see, there is a first name "Genevive" in the list.
It is that "" in the name which isn't handled as is should.
In the web page the name appears as "Genevi" + a small square behind it. The rest ("ve") is gone. It's clearly the in the text that causes the problem.

The code I use :

$fcontents = file('qry/q_000190.txt');

for($i=0; $i<count($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode("\t", $line);
}

With the function file() I read the complete file into memory.
After that, I use explode with parameter \t in a loop to get the tab separated data into an array.

Then I can use that array to fill a table with the data on the webpage.

Does anyone know what goes wrong, or how to solve the problem?

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:37 PM

Posted 21 October 2011 - 09:08 AM

I am at work so I can't go into depth on this right now, but basically you are going to want to look at this: http://php.net/manual/en/function.htmlspecialchars.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users