Changeset 605 for trunk/lib


Ignore:
Timestamp:
May 19, 2017 2:49:13 PM (7 years ago)
Author:
anonymous
Message:

Add function conditionalUTF8Encode()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r601 r605  
    135135    return $output;
    136136}
     137
     138/**
     139 * @param string|mixed $value A string to UTF8-encode.
     140 *
     141 * @returns string|mixed The UTF8-encoded string, or the object passed in if
     142 *    it wasn't a string.
     143 */
     144function conditionalUTF8Encode($value)
     145{
     146  if (is_string($value) && mb_detect_encoding($value, 'UTF-8', true) != 'UTF-8') {
     147    return utf8_encode($value);
     148  } else {
     149    return $value;
     150  }
     151}
     152
    137153
    138154/**
Note: See TracChangeset for help on using the changeset viewer.