source-function-F_isURL

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Interfaces

Exceptions

Functions

  1: <?php
  2: //============================================================+
  3: // File name   : tce_functions_general.php
  4: // Begin       : 2001-09-08
  5: // Last Update : 2014-02-03
  6: //
  7: // Description : General functions.
  8: //
  9: // Author: Nicola Asuni
 10: //
 11: // (c) Copyright:
 12: //               Nicola Asuni
 13: //               Tecnick.com LTD
 14: //               www.tecnick.com
 15: //               info@tecnick.com
 16: //
 17: // License:
 18: //    Copyright (C) 2004-2013 Nicola Asuni - Tecnick.com LTD
 19: //    See LICENSE.TXT file for more information.
 20: //============================================================+
 21: 
 22: /**
 23:  * @file
 24:  * General functions.
 25:  * @package com.tecnick.tcexam.shared
 26:  * @author Nicola Asuni
 27:  * @since 2001-09-08
 28:  */
 29: 
 30: /**
 31:  * Count rows of the given table.
 32:  * @param $dbtable (string) database table name
 33:  * @param $where (string) optional where SQL clause (including the WHERE keyword).
 34:  * @return number of rows
 35:  */
 36: function F_count_rows($dbtable, $where = '')
 37: {
 38:     global $db;
 39:     require_once('../config/tce_config.php');
 40:     $numofrows = 0;
 41:     $sql = 'SELECT COUNT(*) AS numrows FROM '.$dbtable.' '.$where.'';
 42:     if ($r = F_db_query($sql, $db)) {
 43:         if ($m = F_db_fetch_array($r)) {
 44:             $numofrows = $m['numrows'];
 45:         }
 46:     } else {
 47:         F_display_db_error();
 48:     }
 49:     return($numofrows);
 50: }
 51: 
 52: /**
 53:  * Prepare field value for SQL query.<br>
 54:  * Returns the quoted string if not empty, NULL otherwise.
 55:  * @param $str (string) string to check.
 56:  * @return string $str quoted if not empty, NULL otherwise
 57:  */
 58: function F_empty_to_null($str)
 59: {
 60:     global $db;
 61:     require_once('../../shared/code/tce_db_dal.php');
 62:     if (strlen($str) > 0) {
 63:         return '\''.F_escape_sql($db, $str).'\'';
 64:     }
 65:     return 'NULL';
 66: }
 67: 
 68: /**
 69:  * Prepare field value for SQL query.<br>
 70:  * Returns the num if different from zero, NULL otherwise.
 71:  * @param $num (string) string to check.
 72:  * @return string $num if != 0, NULL otherwise
 73:  */
 74: function F_zero_to_null($num)
 75: {
 76:     global $db;
 77:     require_once('../../shared/code/tce_db_dal.php');
 78:     if ($num == 0) {
 79:         return 'NULL';
 80:     }
 81:     return F_escape_sql($db, $num);
 82: }
 83: 
 84: /**
 85:  * Returns boolean value from string or integer.<br>
 86:  * This function is needed to get the right boolean value from boolean field returned by PostgreSQL query.
 87:  * @param $str (string) string to check.
 88:  * @return boolean value.
 89:  */
 90: function F_getBoolean($str)
 91: {
 92:     if (is_bool($str)) {
 93:         return $str;
 94:     }
 95:     if (is_string($str) and ((strncasecmp($str, 't', 1) == 0) or (strncasecmp($str, '1', 1) == 0))) {
 96:         return true;
 97:     }
 98:     if (is_int($str) and ($str == 1)) {
 99:         return true;
100:     }
101:     return false;
102: }
103: 
104: /**
105:  * Check if specified fields are unique on table.
106:  * @param $table (string) table name
107:  * @param $where (string) SQL where clause
108:  * @param $fieldname (mixed) name of table column to check
109:  * @param $fieldid (mixed) ID of table row to check
110:  * @return bool true if unique, false otherwise
111:  */
112: function F_check_unique($table, $where, $fieldname = false, $fieldid = false)
113: {
114:     require_once('../config/tce_config.php');
115:     global $l, $db;
116:     $sqlc = 'SELECT * FROM '.$table.' WHERE '.$where.' LIMIT 1';
117:     if ($rc = F_db_query($sqlc, $db)) {
118:         if (($fieldname === false) and ($fieldid === false) and (F_count_rows($table, 'WHERE '.$where) > 0)) {
119:             return false;
120:         }
121:         if ($mc = F_db_fetch_array($rc)) {
122:             if ($mc[$fieldname] == $fieldid) {
123:                 return true; // the values are unchanged
124:             }
125:         } else {
126:             // the new values are not yet present on table
127:             return true;
128:         }
129:     } else {
130:         F_display_db_error();
131:     }
132:     // another table row contains the same values
133:     return false;
134: }
135: 
136: /**
137:  * Reverse function for htmlentities.
138:  * @param $text_to_convert (string) input string to convert
139:  * @param $preserve_tagsign (boolean) if true preserve <> symbols, default=FALSE
140:  * @return converted string
141:  */
142: function unhtmlentities($text_to_convert, $preserve_tagsign = false)
143: {
144:     if ($preserve_tagsign) {
145:         $text_to_convert = preg_replace('/\&([gl])t;/', '&amp;\\1t;', $text_to_convert);
146:     }
147:     return @html_entity_decode($text_to_convert, ENT_NOQUOTES | ENT_XHTML, 'UTF-8');
148: }
149: 
150: /**
151:  * Remove the following characters:
152:  * <ul>
153:  * <li>"\t" (ASCII 9 (0x09)), a tab.</li>
154:  * <li>"\n" (ASCII 10 (0x0A)), a new line (line feed)</li>
155:  * <li>"\r" (ASCII 13 (0x0D)), a carriage return</li>
156:  * <li>"\0" (ASCII 0 (0x00)), the NUL-byte</li>
157:  * <li>"\x0B" (ASCII 11 (0x0B)), a vertical tab</li>
158:  * </ul>
159:  * @param $string (string) input string to convert
160:  * @param $dquotes (boolean) If true add slash in fron of double quotes;
161:  * @return converted string
162:  */
163: function F_compact_string($string, $dquotes = false)
164: {
165:     $repTable = array("\t" => ' ', "\n" => ' ', "\r" => ' ', "\0" => ' ', "\x0B" => ' ');
166:     if ($dquotes) {
167:         $repTable['"'] = '&quot;';
168:     }
169:     return strtr($string, $repTable);
170: }
171: 
172: /**
173:  * Replace angular parenthesis with html equivalents (html entities).
174:  * @param $str (string) input string to convert
175:  * @return converted string
176:  */
177: function F_replace_angulars($str)
178: {
179:     $replaceTable = array('<' => '&lt;', '>' => '&gt;');
180:     return strtr($str, $replaceTable);
181: }
182: 
183: /**
184:  * Performs a multi-byte safe substr() operation based on number of characters.
185:  * @param $str (string) input string
186:  * @param $start (int) substring start index
187:  * @param $length (int) substring max lenght
188:  * @return substring
189:  */
190: function F_substr_utf8($str, $start = 0, $length)
191: {
192:     $str .= ''; // force $str to be a string
193:     $bytelen = strlen($str);
194:     $i = 0;
195:     $j = 0;
196:     $str_start = 0;
197:     $str_end = $bytelen;
198:     while ($i < $bytelen) {
199:         if ($j == $start) {
200:             $str_start = $i;
201:         } elseif ($j == $length) {
202:             $str_end = $i;
203:             break;
204:         }
205:         $char = ord($str{$i}); // get one string character at time
206:         if ($char <= 0x7F) {
207:             $i += 1;
208:         } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
209:             $i += 2;
210:         } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
211:             $i += 3;
212:         } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
213:             $i += 4;
214:         } else {
215:             $i += 1;
216:         }
217:         ++$j;
218:     }
219:     $str = substr($str, $str_start, $str_end);
220:     return $str;
221: }
222: 
223: /**
224:  * Escape some special characters (&lt; &gt; &amp;).
225:  * @param $str (string) input string to convert
226:  * @return converted string
227:  */
228: function F_text_to_xml($str)
229: {
230:     $replaceTable = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
231:     return strtr($str, $replaceTable);
232: }
233: 
234: /**
235:  * Unescape some special characters (&lt; &gt; &amp;).
236:  * @param $str (string) input string to convert
237:  * @return converted string
238:  */
239: function F_xml_to_text($str)
240: {
241:     $replaceTable = array('&amp;' => '&', '&lt;' => '<', '&gt;' => '>');
242:     return strtr($str, $replaceTable);
243: }
244: 
245: /**
246:  * Escape some special characters for TSV output.
247:  * @param $str (string) input string to convert
248:  * @return converted string
249:  */
250: function F_text_to_tsv($str)
251: {
252:     $replaceTable = array("\0" => '', "\t" => '\t', "\n" => '\n', "\r" => '\r');
253:     return strtr($str, $replaceTable);
254: }
255: 
256: /**
257:  * Unescape some special characters from TSV format.
258:  * @param $str (string) input string to convert
259:  * @return converted string
260:  */
261: function F_tsv_to_text($str)
262: {
263:     $replaceTable = array('\t' => "\t", '\n' => "\n", '\r' => "\r");
264:     return strtr($str, $replaceTable);
265: }
266: 
267: /**
268:  * Return a string containing an HTML acronym for required/not required fields.
269:  * @param $mode (int) field mode: 1=not required; 2=required.
270:  * @return html string
271:  */
272: function showRequiredField($mode = 1)
273: {
274:     global $l;
275:     $str = '';
276:     if ($mode == 2) {
277:         $str = ' <acronym class="requiredonbox" title="'.$l['w_required'].'">+</acronym>';
278:     } else {
279:         $str = ' <acronym class="requiredoffbox" title="'.$l['w_not_required'].'">-</acronym>';
280:     }
281:     return $str;
282: }
283: 
284: /**
285:  * Strip whitespace (or other characters) from the beginning and end of an UTF-8 string and replace the "\xA0" with normal space.
286:  * @param $txt (string) The string that will be trimmed.
287:  * @return string The trimmed string.
288:  */
289: function utrim($txt)
290: {
291:     $txt = preg_replace('/\xA0/u', ' ', $txt);
292:     $txt = preg_replace('/^([\s]+)/u', '', $txt);
293:     $txt = preg_replace('/([\s]+)$/u', '', $txt);
294:     return $txt;
295: }
296: 
297: /**
298:  * Convert all IP addresses to IPv6 expanded notation.
299:  * @param $ip (string) IP address to normalize.
300:  * @return string IPv6 address in expanded notation or false in case of invalid input.
301:  * @since 7.1.000 (2009-02-13)
302:  */
303: function getNormalizedIP($ip)
304: {
305:     if (($ip == '0000:0000:0000:0000:0000:0000:0000:0001') or ($ip == '::1')) {
306:         // fix localhost problem
307:         $ip = '127.0.0.1';
308:     }
309:     $ip = strtolower($ip);
310:     // remove unsupported parts
311:     if (($pos = strrpos($ip, '%')) !== false) {
312:         $ip = substr($ip, 0, $pos);
313:     }
314:     if (($pos = strrpos($ip, '/')) !== false) {
315:         $ip = substr($ip, 0, $pos);
316:     }
317:     $ip = preg_replace("/[^0-9a-f:\.]+/si", '', $ip);
318:     // check address type
319:     $is_ipv6 = (strpos($ip, ':') !== false);
320:     $is_ipv4 = (strpos($ip, '.') !== false);
321:     if ((!$is_ipv4) and (!$is_ipv6)) {
322:         return false;
323:     }
324:     if ($is_ipv6 and $is_ipv4) {
325:         // strip IPv4 compatibility notation from IPv6 address
326:         $ip = substr($ip, strrpos($ip, ':') + 1);
327:         $is_ipv6 = false;
328:     }
329:     if ($is_ipv4) {
330:         // convert IPv4 to IPv6
331:         $ip_parts = array_pad(explode('.', $ip), 4, 0);
332:         if (count($ip_parts) > 4) {
333:             return false;
334:         }
335:         for ($i = 0; $i < 4; ++$i) {
336:             if ($ip_parts[$i] > 255) {
337:                 return false;
338:             }
339:         }
340:         $part7 = base_convert(($ip_parts[0] * 256) + $ip_parts[1], 10, 16);
341:         $part8 = base_convert(($ip_parts[2] * 256) + $ip_parts[3], 10, 16);
342:         $ip = '::ffff:'.$part7.':'.$part8;
343:     }
344:     // expand IPv6 notation
345:     if (strpos($ip, '::') !== false) {
346:         $ip = str_replace('::', str_repeat(':0000', (8 - substr_count($ip, ':'))).':', $ip);
347:     }
348:     if (strpos($ip, ':') === 0) {
349:         $ip = '0000'.$ip;
350:     }
351:     // normalize parts to 4 bytes
352:     $ip_parts = explode(':', $ip);
353:     foreach ($ip_parts as $key => $num) {
354:         $ip_parts[$key] = sprintf('%04s', $num);
355:     }
356:     $ip = implode(':', $ip_parts);
357:     return $ip;
358: }
359: 
360: /**
361:  * Converts a string containing an IP address into its integer value.
362:  * @param $ip (string) IP address to convert.
363:  * @return int IP address as integer number.
364:  * @since 7.1.000 (2009-02-13)
365:  */
366: function getIpAsInt($ip)
367: {
368:     $ip = getNormalizedIP($ip);
369:     $ip = str_replace(':', '', $ip);
370:     return hexdec($ip);
371: }
372: 
373: /**
374:  * Converts a string containing an IP address into its integer value and return string representation.
375:  * @param $ip (string) IP address to convert.
376:  * @return int IP address as string.
377:  * @since 9.0.033 (2009-11-03)
378:  */
379: function getIpAsString($ip)
380: {
381:     $ip = getIpAsInt($ip);
382:     return sprintf('%.0f', $ip);
383: }
384: 
385: /**
386:  * Format a percentage number.
387:  * @param $num (float) number to be formatted
388:  * @return formatted string
389:  */
390: function F_formatFloat($num)
391: {
392:     return sprintf('%.03f', round($num, 3));
393: }
394: 
395: /**
396:  * Format a percentage number.
397:  * @param $num (float) Number to be formatted.
398:  * @param $ratio (boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.
399:  * @return formatted string
400:  */
401: function F_formatPercentage($num, $ratio = true)
402: {
403:     if ($ratio) {
404:         $num = (100 * $num);
405:     }
406:     return '('.str_replace(' ', '&nbsp;', sprintf('% 3d', round($num))).'%)';
407: }
408: 
409: /**
410:  * format a percentage number
411:  * @param $num (float) number to be formatted
412:  * @param $ratio (boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.
413:  * @return string
414:  */
415: function F_formatPdfPercentage($num, $ratio = true)
416: {
417:     if ($ratio) {
418:         $num = (100 * $num);
419:     }
420:     return '('.sprintf('% 3d', round($num)).'%)';
421: }
422: 
423: 
424: /**
425:  * format a percentage number for XML
426:  * @param $num (float) number to be formatted
427:  * @param $ratio (boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.
428:  * @return string
429:  */
430: function F_formatXMLPercentage($num, $ratio = true)
431: {
432:     if ($ratio) {
433:         $num = (100 * $num);
434:     }
435:     return sprintf('%3d', round($num));
436: }
437: 
438: /**
439:  * Returns the UTC time offset in seconds
440:  * @param $timezone (string) current user timezone
441:  * @return int UTC time offset in seconds
442:  */
443: function F_getUTCoffset($timezone)
444: {
445:     $user_timezone = new DateTimeZone($timezone);
446:     $user_datetime = new DateTime('now', $user_timezone);
447:     return $user_timezone->getOffset($user_datetime);
448: }
449: 
450: /**
451:  * Returns the UTC time offset yo be used with CONVERT_TZ function
452:  * @param $timezone (string) current user timezone
453:  * @return string UTC time offset (+HH:mm)
454:  */
455: function F_db_getUTCoffset($timezone)
456: {
457:     $time_offset = F_getUTCoffset($timezone);
458:     $sign = ($time_offset >= 0)?'+':'-';
459:     return $sign.gmdate('H:i', abs($time_offset));
460: }
461: 
462: /**
463:  * Get data array in XML format.
464:  * @param $data (array) Array of data (key => value).
465:  * @param $level (int) Indentation level.
466:  * @return string XML data
467:  */
468: function getDataXML($data, $level = 1)
469: {
470:     $xml = '';
471:     $tb = str_repeat("\t", $level);
472:     foreach ($data as $key => $value) {
473:         $key = strtolower($key);
474:         $key = preg_replace('/[^a-z0-9]+/', '_', $key);
475:         if (is_numeric($key[0]) or ($key[0] == '_')) {
476:             $key = 'item'.$key;
477:         }
478:         $xml .= $tb.'<'.$key.'>';
479:         if (is_array($value)) {
480:             $xml .= "\n".getDataXML($value, ($level + 1));
481:         } else {
482:             $xml .= F_text_to_xml($value);
483:         }
484:         $xml .= '</'.$key.'>'."\n";
485:     }
486:     return $xml;
487: }
488: 
489: /**
490:  * Get data headers (keys) in TSV header (tab separated text values).
491:  * @param $data (array) Array of data (key => value).
492:  * @param $prefix (string) Prefix to add to keys.
493:  * @return string data
494:  */
495: function getDataTSVHeader($data, $prefix = '')
496: {
497:     $tsv = '';
498:     foreach ($data as $key => $value) {
499:         if (is_array($value)) {
500:             $tsv .= getDataTSVHeader($value, $prefix.$key.'_');
501:         } else {
502:             $tsv .= "\t".$prefix.$key;
503:         }
504:     }
505:     return $tsv;
506: }
507: 
508: /**
509:  * Get data in TSV format (tab separated text values).
510:  * @param $data (array) Array of data.
511:  * @return string XML data
512:  */
513: function getDataTSV($data)
514: {
515:     $tsv = '';
516:     foreach ($data as $value) {
517:         if (is_array($value)) {
518:             $tsv .= getDataTSV($value);
519:         } else {
520:             $tsv .= "\t".F_text_to_tsv($value);
521:         }
522:     }
523:     return $tsv;
524: }
525: 
526: /**
527:  * Convert HTML code to TSV string.
528:  * @param $str (string) HTML string to convert.
529:  * @return string TSV
530:  */
531: function F_html_to_TSV($str)
532: {
533:     $dollar_replacement = ":.dlr.:"; //string replacement for dollar symbol
534:     //tags conversion table
535:     $tags2textTable = array (
536:         "'<br[^>]*?>'i" => ' ',
537:         "'<table[^>]*?>'i" => "\n",
538:         "'</table>'i" => "\n",
539:         "'<tr[^>]*?>'i" => "\n",
540:         "'<th[^>]*?>'i" => "\t",
541:         "'<td[^>]*?>'i" => "\t",
542:         "'<h[0-9][^>]*?>'i" => "\n\n",
543:         "'</h[0-9]>'i" => "\n"
544:     );
545:     $str = str_replace('&nbsp;', ' ', $str);
546:     $str = str_replace('&rarr;', '-', $str);
547:     $str = str_replace('&darr;', '', $str);
548:     $str = str_replace("\t", ' ', $str);
549:     $str = preg_replace_callback('/colspan="([0-9]*)"/x', create_function('$matches', 'if ($matches[1] > 1) {return str_repeat("></td><td", ($matches[1] - 1));} return "";'), $str);
550:     $str = str_replace("\r\n", "\n", $str);
551:     $str = str_replace("\$", $dollar_replacement, $str); //replace special character
552:     //remove newlines
553:     $str = str_replace("\n", '', $str);
554:     $str = preg_replace(array_keys($tags2textTable), array_values($tags2textTable), $str);
555:     $str = preg_replace("'<[^>]*?>'si", '', $str); //strip out remaining tags
556:     //remove some newlines in excess
557:     $str = preg_replace("'[ \t\f]+[\r\n]'si", "\n", $str);
558:     $str = preg_replace("'[\r\n][\r\n]+'si", "\n\n", $str);
559:     $str = unhtmlentities($str, false);
560:     $str = str_replace($dollar_replacement, "\$", $str); //restore special character
561:     $str = rtrim($str);
562:     $str = ltrim($str, " \r\n\0\x0B");
563:     $str = stripslashes($str);
564:     return $str;
565: }
566: 
567: /**
568:  * Display table header element with order link.
569:  * @param $order_field (string) name of table field
570:  * @param $orderdir (string) order direction
571:  * @param $title title (string) field of anchor link
572:  * @param $name column (string) name
573:  * @param $current_order_field (string) current order field name
574:  * @param $filter (string) additional parameters to pass on URL
575:  * @return table header element string
576:  */
577: function F_select_table_header_element($order_field, $orderdir, $title, $name, $current_order_field = '', $filter = '')
578: {
579:     global $l;
580:     require_once('../config/tce_config.php');
581:     $ord = '';
582:     if ($order_field == $current_order_field) {
583:         if ($orderdir == 1) {
584:             $ord = ' <acronym title="'.$l['w_ascent'].'">&gt;</acronym>';
585:         } else {
586:             $ord = ' <acronym title="'.$l['w_descent'].'">&lt;</acronym>';
587:         }
588:     }
589:     $str = '<th><a href="'.$_SERVER['SCRIPT_NAME'].'?'.$filter.'&amp;firstrow=0&amp;order_field='.$order_field.'&amp;orderdir='.$orderdir.'" title="'.$title.'">'.$name.'</a>'.$ord.'</th>'."\n";
590:     return $str;
591: }
592: 
593: /**
594:  * Get a black or white color that maximize contrast.
595:  * @param $color (string) color in HEX format.
596:  * @return (string) Color.
597:  */
598: function getContrastColor($color)
599: {
600:     $r = hexdec(substr($color, 0, 2));
601:     $g = hexdec(substr($color, 2, 2));
602:     $b = hexdec(substr($color, 4, 2));
603:     // brightness of the selected color
604:     $br = (((299 * $r) + (587 * $g) + (114 * $b)) / 1000);
605:     if ($br < 128) {
606:         // white
607:         return 'ffffff';
608:     }
609:     // black
610:     return '000000';
611: }
612: 
613: /**
614:  * Returns true if the string is an URL.
615:  * @param $str (string) String to check.
616:  * @return boolean true or false.
617:  */
618: function F_isURL($str)
619: {
620:     if ((preg_match('/^(ftp|http|https|mail|sftp|ssh|telnet|vnc)[:][\/][\/]/', $str) > 0) and (parse_url($str) !== false)) {
621:         return true;
622:     }
623:     return false;
624: }
625: 
626: /**
627:  * Normalize the UTF-8 input string.
628:  * Modes greater than 0 requires php5-intl module.
629:  * Please edit this function to implement your custom normalization method.
630:  * @param $str (string) UTF-8 string to normalize.
631:  * @param $mode (int) Normalization type: NONE=None; C=Normalization Form C (NFC) - Canonical Decomposition followed by Canonical Composition; D=Normalization Form D (NFD) - Canonical Decomposition; KC=Normalization Form KC (NFKC) - Compatibility Decomposition, followed by Canonical Composition; KD=Normalization Form KD (NFKD) - Compatibility Decomposition; CUSTOM=Custom normalization using user defined function 'user_utf8_custom_normalizer'.
632:  * @return normalized string using the specified algorithm.
633:  */
634: function F_utf8_normalizer($str, $mode = 'NONE')
635: {
636:     switch ($mode) {
637:         case 'CUSTOM': {
638:             if (function_exists('user_utf8_custom_normalizer')) {
639:                 return call_user_func('user_utf8_custom_normalizer', $str);
640:             } else {
641:                 return $str;
642:             }
643:             break;
644:         }
645:         case 'C': {
646:             // Normalization Form C (NFC) - Canonical Decomposition followed by Canonical Composition
647:             return normalizer_normalize($str, Normalizer::FORM_C);
648:             break;
649:         }
650:         case 'D': {
651:             // Normalization Form D (NFD) - Canonical Decomposition
652:             return normalizer_normalize($str, Normalizer::FORM_D);
653:             break;
654:         }
655:         case 'KC': {
656:             // Normalization Form KC (NFKC) - Compatibility Decomposition, followed by Canonical Composition
657:             return normalizer_normalize($str, Normalizer::FORM_KC);
658:             break;
659:         }
660:         case 'KD': {
661:             // Normalization Form KD (NFKD) - Compatibility Decomposition
662:             return normalizer_normalize($str, Normalizer::FORM_KD);
663:             break;
664:         }
665:         case 'NONE':
666:         default: {
667:             return $str;
668:             break;
669:         }
670:     }
671: }
672: 
673: /**
674:  * Convert an long integer number to a Hexadecimal representation
675:  * @param string|int $dec Decimal number to convert.
676:  * @return string containing the HEX representation in uppercase.
677:  * @author Nicola Asuni
678:  * @since 2013-07-02
679:  */
680: function bcdechex($dec)
681: {
682:     $last = bcmod($dec, 16);
683:     $remain = bcdiv(bcsub($dec, $last), 16);
684:     if ($remain == 0) {
685:         return strtoupper(dechex($last));
686:     } else {
687:         return bcdechex($remain).strtoupper(dechex($last));
688:     }
689: }
690: 
691: //============================================================+
692: // END OF FILE
693: //============================================================+
694: 
 

© 2004-2018 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy