Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: utf8

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5

File/phputf8/utils/ascii.php

Description

Tools to help with ASCII in UTF-8

Functions
utf8_accents_to_ascii (line 190)

Replace accented UTF-8 characters by unaccented ASCII-7 "equivalents".

The purpose of this function is to replace characters commonly found in Latin alphabets with something more or less equivalent from the ASCII range. This can be useful for converting a UTF-8 to something ready for a filename, for example. Following the use of this function, you would probably also pass the string through utf8_strip_non_ascii to clean out any other non-ASCII chars Use the optional parameter to just deaccent lower ($case = -1) or upper ($case = 1) letters. Default is to deaccent both cases ($case = 0)

  • return: accented chars replaced with ascii equivalents
  • author: Andreas Gohr <[email protected]>
string utf8_accents_to_ascii (string $str, [int $case = 0], string 2)
  • string 2: UTF-8 with accented characters replaced by ASCII chars
  • string $str: UTF-8 string
  • int $case: (optional) -1 lowercase only, +1 uppercase only, 1 both cases
utf8_is_ascii (line 91)

Tests whether a string contains only 7bit ASCII bytes.

You might use this to conditionally check whether a string needs handling as UTF-8 or not, potentially offering performance benefits by using the native PHP equivalent if it's just ASCII e.g.;

  1.  <?php
  2.  if utf8_is_ascii($someString) ) {
  3.      // It's just ASCII - use the native PHP version
  4.           $someString strtolower($someString);
  5.  else {
  6.      $someString utf8_strtolower($someString);
  7.  }
  8.  ?>

boolean utf8_is_ascii (string $str)
  • string $str
utf8_is_ascii_ctrl (line 111)

Tests whether a string contains only 7bit ASCII bytes with device control codes omitted. The device control codes can be found on the second table here: http://www.w3schools.com/tags/ref_ascii.asp

  • return: TRUE if it's all ASCII without device control codes
  • see: utf8_is_ascii()
boolean utf8_is_ascii_ctrl (string $str)
  • string $str
utf8_strip_non_ascii (line 131)

Strip out all non-7bit ASCII bytes If you need to transmit a string to system which you know can only support 7bit ASCII, you could use this function.

string utf8_strip_non_ascii (string $str)
  • string $str
utf8_strip_non_ascii_ctrl (line 157)

Strip out all non 7bit ASCII bytes and ASCII device control codes.

For a list of ASCII device control codes see the 2nd table here: http://www.w3schools.com/tags/ref_ascii.asp

  • return: TRUE if it's all ASCII
boolean utf8_strip_non_ascii_ctrl (string $str)
  • string $str

Documentation generated on Mon, 05 Mar 2007 20:52:27 +0000 by phpDocumentor 1.3.1