PhpDig.net

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




recode_string

Name

recode_string — Recodes a string according to a recode request.

Synopsis

string recode_string([. . .], text);
string . . . (optional): Recode request (expressed as char_set_from..char_set_to)
string text: Text to be converted

Returns

Recoded string; FALSE if the recode request fails

Description

recode_string() converts a string from one character set to another according to the specified recode request . The recode request should consist of the name of the character set to convert from, followed by two periods and the name of the target character set; for example, to convert from EBCDIC to ASCII, the request is "EBCDIC..ASCII".

If the recode request cannot be handled by recode, the function returns FALSE .

Version

PHP Version: 3.0.13+, 4.0RC1+

See also

recode()

To recode files

recode_file()

Other functions for building internationalized applications in PHP

dbase_delete_record()

Example

Example 1120. Convert a base 64 string to EBCDIC

print recode ('/Base64..EBCDIC', 'SGVsbG8gV29ybGQhDQo=');

Example 1121. Find the diacriticals in a string

<?php
# The names of the winter months in the French Republican Calendar
$hiver = 'Nivse, Pluvise, Ventise';

# Convert from ASCII to ASCII without diacriticals
$recoded = recode_string ('us..flat', $hiver);

# Find the accented characters
for ($x=0; $x < strlen ($hiver); ++$x) {
   if ($hiver[$x] !== $recoded[$x]) {
      $diacriticals[] = $hiver[$x];
   }
}

if (FALSE === is_array ($diacriticals))
   die ("There were no diacritical marks in the string: '$hiver'");

# find the number of diacriticals
$count = count ($diacriticals);

# Convert the array to a comma-separated string
$diacriticals = implode (', ', $diacriticals);

echo "There are $count diacritical marks <i>($diacriticals)</i> in the string: '$hiver'";
?>

Output:
There are 3 diacritical marks (, , ) in the string: 'Nivse, Pluvise, Ventise'



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.