PHP Classes

File: www/ws/v1.0/test.php

Recommend this page to a friend!
  Classes of Adnane EL Mouttaki   Covoiturage Libre   www/ws/v1.0/test.php   Download  
File: www/ws/v1.0/test.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Covoiturage Libre
Web application for managing a carpoling site
Author: By
Last change:
Date: 6 years ago
Size: 1,332 bytes
 

Contents

Class file image Download
<?php
phpinfo
();die;
function
xml_entities($text, $charset = 'Windows-1252'){
    
// Debug and Test
    // $text = "test &amp; &trade; &amp;trade; abc &reg; &amp;reg; &#45;";
  
    // First we encode html characters that are also invalid in xml
   
$text = htmlentities($text, ENT_COMPAT, $charset, false);
  
   
// XML character entity array from Wiki
    // Note: &apos; is useless in UTF-8 or in UTF-16
   
$arr_xml_special_char = array("&quot;","&amp;","&apos;","&lt;","&gt;");
  
   
// Building the regex string to exclude all strings with xml special char
   
$arr_xml_special_char_regex = "(?";
    foreach(
$arr_xml_special_char as $key => $value){
       
$arr_xml_special_char_regex .= "(?!$value)";
    }
   
$arr_xml_special_char_regex .= ")";
  
   
// Scan the array for &something_not_xml; syntax
   
$pattern = "/$arr_xml_special_char_regex&([a-zA-Z0-9]+;)/";
  
   
// Replace the &something_not_xml; with &amp;something_not_xml;
   
$replacement = '&amp;${1}';
    return
preg_replace($pattern, $replacement, $text);
}


function
xml_entity_decode($text, $charset = 'Windows-1252'){
   
// Double decode, so if the value was &amp;trade; it will become Trademark
   
$text = html_entity_decode($text, ENT_COMPAT, $charset);
   
$text = html_entity_decode($text, ENT_COMPAT, $charset);
    return
$text;
}
?>