problem with opening (unicode?) text files.

So, I've been working on a now playing page. What it does is looks through the currenttrack.txt file exported by multi-plugin, puts each line into an array, and then lets me print them.

I've been trying to get it to work, and, for the most part, it does. Problem is, the text file exported by Multi-Plugin is in unicode format. This makes things difficult on my end. Opening the file in notepad looks like a normal file- but in most other editors, it will show boxes between letters.

When I try to copy/paste information, it only displays the first letter of the selection.

Does anyone know how to import a file to be read as unicode, rather than ansi?

Heres the code I'm using to select the text file, and import it as an array.

<?php

$filename="C:program filesitunescurrenttrack.txt";

$lines = array();

$file = fopen($filename, "r");

while(!feof($file)) {



$lines[] = fgets($file, 4096);



}

?>

Any help would be appreciated, as this is quite a mystery

(and if anyone wants to take a look, it's here.)

#415479

if you need to show the text in a webpage, you can tell the browser your page is unicode using something like

header('Content-Type: text/html; charset=UTF-8');

at the beginning of your page. Other program will still show boxes, but the browser now knows and display them properly :)

#415570

Try what dreadnaut said.

If that's not what you're looking for... I've never handled this problem so i'm not entirely sure how to fix it, but you could try:

$filecontents = implode('', file("C:program filesitunescurrenttrack.txt"));

To get the contents of the file as the string $filecontents.

What does that give you?

If there are bits and pieces in there that you don't want, you can use the str_ireplace function to remove whatever you want, like this:

$filecontents = str_ireplace("thing you want to remove", "", "$filecontents");

Then it's easy to just use the explode function to get the artist, title, etc, depending on how the text file is laid out.

$fileparts = explode(' ', $filecontents);
$artist= $fileparts[0]

I'm no expert though :o

#415578

Dreadnaut- A great solution- but I couldn't get it working.

Cdi2 - I understand what your getting at. What I'm doing is breaking the file into an array, and echoing the index of it- so for instance, artist would be like:

echo $lines[1];

I'll give dreadnaut's solution another try and get back to you.

#415684

I tried dreadnaut's solution, and unfortunately it did nothing.

Anyways- another thought I had would be to grab the contents from the original text file and put them into another, save it, and just use that one instead. It works to copy/paste into another notepad and save it.

Unfortunately, I have no idea how to do this- could anyone give me a hand?

#415691

I installed multi-plugin out of curiosity.

Anyhow, found a way to get rid of those pesky boxes.

Rather simple really:

<?php

$text=implode('',file("C:Program FilesiTunesCurrentTrack.txt"));//Gets text

$text=strip_tags($text);//Strips tags (those squares included)

$text=nl2br($text);//Inserts
whenever a new line occurs

$parts= explode("
", $text);// Etc... Etc...

echo "Artist: " . $parts[1] . "
Song: " . $parts[2] . "
Album: " . $parts[3];

?>

That does it. Try it out :D

Stuck it in a function to tidy things up a bit :)

<?php



function info($part){

$text=implode('',file("C:Program FilesiTunesCurrentTrack.txt"));

$text=strip_tags($text);

$text=nl2br($text);

$parts= explode("
", $text);

switch ($part){

case "artist":

echo "Artist: " . $parts[1] . "
";

break;

case "song":

echo "Song: " . $parts[2] . "
";

break;

case "album":

echo "Album: " . $parts[3] . "
";

break;

case "length":

echo "Length: " . $parts[7] . "
";

break;

}}



echo info(artist) . info(song) . info(album);

?>

#415887