rfv123

utility functions: addQuotes and trimQuotes

May 29th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. // ----------------------------------------------------------------------------*
  2. // strip quote marks from a string -- workout which quoutes are used
  3. function trimQuotes($expr, $quoteChar='?')
  4. {
  5.     $exprChar = substr($expr, 0, 1);
  6.     if (    $quoteChar === '?'
  7.          && strpos('\'\"', $exprChar) !== false) {
  8.         $quoteChar = $exprChar;
  9.     }
  10.     return  trim($expr, $quoteChar);
  11. }
  12.  
  13. // ----------------------------------------------------------------------------*
  14. // add double quote marks to a string check that it doesn't have them already.
  15. function addQuotes($expr, $quotechar='"')
  16. {
  17.     if (substr($expr, 0, 1) != $quotechar) {
  18.       return $quotechar . $expr . $quotechar;
  19.     }
  20.     else {
  21.       return $expr;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment