PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




convert_cyr_string

Name

convert_cyr_string — Converts between Cyrillic character sets.

Synopsis

string conver_cyr_string(string, source, destination);
string string: String to convert
string source: Source character set
string destination: Target character set

Returns

Converted string; if an error occurs, the original string

Description

convert_cyr_string() converts strings from one Cyrillic character set to another. The character sets to be converted are specified with a single character code. The codes correspond to the following character sets.

Symbol Character set
k KOI8-r
w Windows-1251
i ISO8859-5
a x-cp866
d x-cp866
m x-Mac-Cyrillic


If an invalid code is specified for the source() and/or destination() argument, the function generates a warning.

Note

The presence of a null byte (\0) in the string halts the translation at that point.

Version

PHP 3.0.6+, PHP 4+

See also

To convert between different character sets:

recode()



Example

Example 1195. Open a file and save it with a different encoding

// The first file is from phpMyAdmin (http://www.phpwizard.com/projects/phpMyAdmin/)
$file_in  = 'russian-koi8.inc.php3';
$file_out = 'russian-iso8859-5.inc.php3';

$fp = fopen($file_in, 'r')
    or die("Could not open file <i>$file_in</i> for reading.");

// Read the entire contents of the file in one go
$contents = fread($fp, filesize($file_in))
    or die("Could not read the contents of file <i>$file_in</i>.");

fclose($fp);

// Convert the contents of the file from KOI8 to ISO8859-5
$contents = convert_cyr_string($contents, 'k', 'i');

// Write the converted contents out to another file
$fp = fopen($file_out, 'w')
    or die("Could not open file <i>$file_out</i> for writing.");

fputs($fp, $contents)
    or die("Could not write to file <i>$file_out</i>.");

fclose($fp);



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.