RE: [PHP] File handling and different character sets
> -Original Message- > From: Per Eriksson [mailto:[EMAIL PROTECTED] > Sent: Friday, November 23, 2007 7:15 AM > To: php-general@lists.php.net > Subject: [PHP] File handling and different character sets > > Hi, > > I would like to know how you work with the PHP Directory Functions and > different character sets. If I am having a professional view, > well-written code should be able to handle file systems in different > character sets. > > http://se.php.net/manual/sv/ref.dir.php > > Is there a way to write code for listing files from a ISO-8859-1 on a > UTF-8 page? I haven't succeeded with this. > > > Thank you, > > Best Regards > > Per Eriksson > per.eriksson A exist ! se > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php Hi Per, I'm just curious, no matter what encoding I choose (IE and FF switch automatically to UTF-8 as per the page metatag and content-type header) I get funny characters at http://se.php.net/manual/sv/ref.dir.php, I don't know if this is because of the default browser font, because I've tried several ones. My system is Windows XP SP2 Spanish version, but I don't think that's the cause either as it is up to date, and I have even installed support for right to left writing... Ok, I know I can just use wget, save the result and open it in a binary editor to see what are the actual bytes and check for the encoding (I won't... I'm kind of lazy today :D ) Regarding your question, I have these functions I copied from the notes to the extended CHM version of the PHP manual, they are at the mb_convert_encoding function reference and should be in the online version of the manual as well (won't check it... too lazy, I told you)... [snip] volker at machon dot biz (25-Sep-2007 05:05) Hey guys. For everybody who's looking for a function that is converting an iso-string to utf8 or an utf8-string to iso, here's your solution: public function encodeToUtf8($string) { return mb_convert_encoding($string, "UTF-8", mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true)); } public function encodeToIso($string) { return mb_convert_encoding($string, "ISO-8859-1", mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true)); } For me these functions are working fine. Give it a try [/snip] The first thing to test for would be if the directory/filesystem functions are retrieving data encoded in ISO-8859-1 or not (I guess it depends on the OS, but you might know better), otherwise mb_convert_encoding would act like "double escaping" or "double urlencoding" (a known issue for all of us, ha?). That's why encodeToUtf8 uses mb_detect_encoding first... anyway, I wonder if mb_detect_encoding can guarantee you anything other than the byte stream of data being valid in the given character set(s). So... what do you think, did you get any further results about this? And also, do you have any code sample you are working on to share? Regards, Rob Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 | TEL 954-607-4207 | FAX 954-337-2695 | Email: [EMAIL PROTECTED] | MSN Chat: [EMAIL PROTECTED] | SKYPE: bestplace | Web: bestplace.biz | Web: seo-diy.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File handling and different character sets
Hi, I would like to know how you work with the PHP Directory Functions and different character sets. If I am having a professional view, well-written code should be able to handle file systems in different character sets. http://se.php.net/manual/sv/ref.dir.php Is there a way to write code for listing files from a ISO-8859-1 on a UTF-8 page? I haven't succeeded with this. Thank you, Best Regards Per Eriksson per.eriksson A exist ! se -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File-handling
[EMAIL PROTECTED] wrote: > Hi there! > > Can someone explain the major difference between fgets and fopen? Which is > the best together with plain textfiles? and why? fgets can be handy to read a large file one LINE at a time. This is most useful in files that are line-based, such as SQL data dumps, CSV files, text files, config files, etc. when you want to process their contents a line at a time and do something to the data. fget lets you read an arbitrary amount of data -- this is useful if you just want to transfer the data from point A to B without interpreting it, or if the data is binary and has some sort of internal byte-structure you need to tear apart to process it. For small files, you might as well just use http://php.net/file or other functions that deal with the whole file at once -- You only really want to mess with fopen/fget|fgets/fclose if you have files that could potentially be HUGE, and you can read a chunk at a time, deal with it, and read some more -- Avoiding trying to suck the whole thing into RAM all at once. > When using fget. Is it something special you should think when taking care > of line-breaks? (/n, /r/n ...) If your data could potentially be coming from Mac, PC, and/or Linux instead of just one platform, you'll have to write some code to figure out what to do with line-breaks. Since I'm always on Linux servers, I generally do: $data = str_replace("\r\n", "\n", $data); //PC -> Linux $data = str_replace("\r", "\n", $data); //Mac -> Linux This converts everything to Linux format, which is what I'll use internally. Note that the order of the two lines is crucial -- If you flip-flop them, you'll make a real mess. If you're not trying to change the data, nor interpret it, you needn't worry about the newlines. > eof and feof. What's the difF? *don't get it* EOF is an acronym for End Of File. feof is the function used to determine if a file has reached its EOF -- that is, if you have successfully read all of the data, and there is no more data to read, and the file still seems kosher, so you're DONE. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File-handling
fgets uses the resource created by fopen. Read the manual: http://it.php.net/fopen http://it.php.net/fgets look at the example: Ian On Fri, 2004-12-17 at 11:24 +0100, [EMAIL PROTECTED] wrote: > Hi there! > > Can someone explain the major difference between fgets and fopen? Which is > the best together with plain textfiles? and why? > > eof and feof. What's the difF? *don't get it* > > When using fget. Is it something special you should think when taking care > of line-breaks? (/n, /r/n ...) > > /G > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File-handling
Hi there! Can someone explain the major difference between fgets and fopen? Which is the best together with plain textfiles? and why? eof and feof. What's the difF? *don't get it* When using fget. Is it something special you should think when taking care of line-breaks? (/n, /r/n ...) /G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File handling
This one time, at band camp, Kenneth Suralta <[EMAIL PROTECTED]> wrote: > How do i delete all file in a directory??? bit ugly but... function del_dir($dirname) { $dh = opendir($dirname); while(false !== ($file = readdir($dh))) { if($file != '.' && $file != '..') { $path = $dirname.'/'.$file; if(is_dir($path)) { del_dir($path); } else { @unlink($path); } } } if(@rmdir($dirname)==true) { echo $dirname.' deleted successfully'; } else { echo 'Unable to delete directory '.$dirname.''; } } if(file_exists($dirname)) { del_dir($dirname); } else { echo 'Directory '.$dirname.' does not exist'; } or something Kevin -- __ (_ \ _) ) | / / _ ) / _ | / ___) / _ ) | | ( (/ / ( ( | |( (___ ( (/ / |_| \) \_||_| \) \) Kevin Waterson Port Macquarie, Australia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] File handling
> How do i delete all file in a directory??? > You could use a function like this: (html code at end) function delFiles($filter, $sDir) { $cDirectory = includeTrailingSlash($sDir); $handle = opendir($cDirectory); while ($file = readdir($handle)) { if ($file == '.' || $file == '..') { continue; } if (is_dir($cDirectory . $file)) { echo "ignoring $cDirectory$file "; delFiles($filter, $cDirectory . $file); continue; } if (eregi($filter, $file)) { echo " deleting $cDirectory$file "; unlink($cDirectory . $file); } } closedir($handle); } function includeTrailingSlash($path) { if (!eregi("/$", $path)) { $path .= "/"; } return $path; } // delete all the .htm files in this directory and it's sub directories $sDir="the directory you want to delete files in"; delFiles("\.htm$", $sDir); //where\.htm$ is the filter you are applying echo "done deleting old files "; hth -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File handling
How do i delete all file in a directory??? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File handling
loop through the file line by line explode()ing every line with "TEXt" in it. Then, if retrning array count is bigger than one, unset() the key one and break the loop. All read OVERWRITE in the original file. Sorry, too lazy writing the code here :) -- Maxim Maletsky [EMAIL PROTECTED] "Jeff" <[EMAIL PROTECTED]> wrote... : > Quick one, how do i read a file for a key word, say "TEXt", and the delete > the rest of the remaining file? > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File handling
on 29/11/02 7:06 PM, Jeff RingRose ([EMAIL PROTECTED]) wrote: > Justin, > Option b. delete all AFTER "foo", I.E. truncate the file directly after > "foo". Leaving "foo" and all the data before "foo" untouched. And what happens if there are more than one occurrence of "foo"? I assume you mean the first occurrence. And what happens if "foo" is found within another word, like "aafooaa"... this example assumes this doesn't matter... it's looking for 'foo', not ' foo '. One of way is to read the file into a variable, split the var on "foo", and rewrite the file out. 1. Totally untested code, but most of it was lifted out of the manual in some way or another. 2. Permissions of the file to be read/written will need to be correct 3. I've included no error reporting or correct checking... you'll need to add this yourself Season to taste... Justin French http://Indent.com.au Web Development & Graphic Design -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File handling
I've got this coed but it still don't do the business: $MESSAGE_FILE="foobar.txt"; $handle=fopen("$MESSAGE_FILE","w"); $sizez= sizeof($handle); $string= 'foo'; while ( fgets($handle,$sisez) { fputs($handle,$sizez); if (strstr($handle,$string)){ break; } } Any ideas? "Jeff Ringrose" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Justin, > Option b. delete all AFTER "foo", I.E. truncate the file directly after > "foo". Leaving "foo" and all the data before "foo" untouched. > > Jeff > > -Original Message----- > From: Justin French [mailto:[EMAIL PROTECTED]] > Sent: 29 November 2002 04:29 > To: Jeff; [EMAIL PROTECTED] > Subject: Re: [PHP] File handling > > > > Quick one, how do i read a file for a key word, say "TEXt", and the delete > > the rest of the remaining file? > > > Do you mean: > > a) how do i make sure a word (eg "foo") is in a file, and if it is, delete > all contents of the file except the word "foo" OR > > b) how do i search a file for the word "foo", and delete everything in the > file AFTER the word "foo" > > ?? > > > Justin French > > http://Indent.com.au > Web Development & > Graphic Design > > > > DISCLAIMER: The information in this message is confidential and may be > legally privileged. It is intended solely for the addressee. Access to this > message by anyone else is unauthorised. If you are not the intended > recipient, any disclosure, copying, or distribution of the message, or any > action or omission taken by you in reliance on it, is prohibited and may be > unlawful. Please immediately contact the sender if you have received this > message in error. Thank you. > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] File handling
Justin, Option b. delete all AFTER "foo", I.E. truncate the file directly after "foo". Leaving "foo" and all the data before "foo" untouched. Jeff -Original Message- From: Justin French [mailto:[EMAIL PROTECTED]] Sent: 29 November 2002 04:29 To: Jeff; [EMAIL PROTECTED] Subject: Re: [PHP] File handling > Quick one, how do i read a file for a key word, say "TEXt", and the delete > the rest of the remaining file? Do you mean: a) how do i make sure a word (eg "foo") is in a file, and if it is, delete all contents of the file except the word "foo" OR b) how do i search a file for the word "foo", and delete everything in the file AFTER the word "foo" ?? Justin French http://Indent.com.au Web Development & Graphic Design DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File handling
> Quick one, how do i read a file for a key word, say "TEXt", and the delete > the rest of the remaining file? Do you mean: a) how do i make sure a word (eg "foo") is in a file, and if it is, delete all contents of the file except the word "foo" OR b) how do i search a file for the word "foo", and delete everything in the file AFTER the word "foo" ?? Justin French http://Indent.com.au Web Development & Graphic Design -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File handling
Quick one, how do i read a file for a key word, say "TEXt", and the delete the rest of the remaining file? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Handling
On Thu, 16 May 2002, karthikeyan wrote: > Just assume that I have a text file with a separator like "|" > > It would be something like this > > "ImagePath" | "DialogName" | "Dialog location" > > I have to read the text file of above format and display in the html file. > > DialogName1 > DialogName2 > DialogName3 http://php.net/fopen http://php.net/fgets http://php.net/explode miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File Handling
Dear All, Greetings. Please let me know if the following can be done with php. All I need to do is this, Just assume that I have a text file with a separator like "|" It would be something like this "ImagePath" | "DialogName" | "Dialog location" I have to read the text file of above format and display in the html file. DialogName1 DialogName2 DialogName3 Thank you With Regards karthikeyan - Judge not, that ye be not Judged - Abraham Lincoln's favorite quote -