Advertisement
giovani_rubim

Untitled

Jan 28th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. <?php
  2.    
  3.     function toJSString ($string) {
  4.  
  5.         $result='"';
  6.  
  7.         for ($i=0; $i<strlen($string); $i++) {
  8.  
  9.             if ($string[$i] == '"') {
  10.  
  11.                 $result .= '\\"';
  12.  
  13.             } else if ($string[$i] == '\\') {
  14.  
  15.                 $result .= '\\\\';
  16.  
  17.             } else {
  18.  
  19.                 $result .= $string[$i];
  20.  
  21.             }
  22.  
  23.         }
  24.  
  25.         return $result.'"';
  26.  
  27.     }
  28.  
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement