home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / odbccharconv.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  1.3 KB  |  50 lines

  1. ODBC char converter 
  2.  
  3. This function will convert characters that ODBC queries have trouble with (apostrophe, quotation mark, back slash) to their HTML special character equivalent before being sent through an SQL query. I wrote this function because the replace function included with PHP threw a lot of exceptions for me. 
  4.  
  5.  
  6. <?PHP 
  7. function conv ($str) { 
  8.   $len = strlen($str); 
  9.   $count = 0; 
  10.   while ($count < $len) 
  11.   { 
  12.     $ordinal = ord($str); 
  13.     if ($ordinal == 92) 
  14.     { 
  15.       $str = substr($str, 1); 
  16.       $ordinal = ord($str); 
  17.        // check for quotation 
  18.       if ($ordinal == 34) 
  19.       { 
  20.     $new_str = $new_str .  """; 
  21.     $str = substr($str, 1); 
  22.     $count = $count + 1; 
  23.       } 
  24.        // check for apostrophe 
  25.       if ($ordinal == 39) 
  26.       { 
  27.     $new_str = $new_str .  "'"; 
  28.     $str = substr($str, 1); 
  29.     $count = $count + 1; 
  30.       } 
  31.        // check for backslash 
  32.       if ($ordinal == 92) 
  33.       { 
  34.     $new_str = $new_str .  "\"; 
  35.     $str = substr($str, 1); 
  36.     $count = $count + 1; 
  37.       } 
  38.     } 
  39.     else 
  40.     { 
  41.       $temp = substr($str, 0, 1); 
  42.       $new_str = $new_str . $temp; 
  43.       $str = substr($str, 1); 
  44.     } 
  45.     $count = $count + 1; 
  46.   } 
  47.   return $new_str; 
  48. ?>
  49.