Skip to content

Commit

Permalink
added PMA_unQuote() to remove quotes from strings
Browse files Browse the repository at this point in the history
  • Loading branch information
CybotTM committed Aug 2, 2006
1 parent 91c0522 commit 179917e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ $Source$
added variables to define (text) color for marked and hovered objects
thanks to Juergen Wind - windkiel for hinting this bug (patch #1503529)
* Documentation.html: updated style config option descriptions
* libraries/common.lib.php: added PMA_escapeJsString() to escape strings for
JavaScript inside CDATA blocks
* libraries/common.lib.php:
- added PMA_escapeJsString() to escape strings for JavaScript inside CDATA blocks
- added PMA_unQuote() to remove quotes from strings
* libraries/footer.inc.php: correctly escape strings inside JavaScript
(part of bug #1532721)

Expand Down
33 changes: 33 additions & 0 deletions libraries/common.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,39 @@ function PMA_unescape_mysql_wildcards($name)
return $name;
} // end of the 'PMA_unescape_mysql_wildcards()' function

/**
* removes quotes (',",`) from a quoted string
*
* checks if the sting is quoted and removes this quotes
*
* @param string $quoted_string string to remove quotes from
* @param string $quote type of quote to remove
* @return string unqoted string
*/
function PMA_unQuote($quoted_string, $quote = null)
{
$quotes = array();

if (null === $quote) {
$quotes[] = '`';
$quotes[] = '"';
$quotes[] = "'";
} else {
$quotes[] = $quote;
}

foreach ($quotes as $quote) {
if (substr($quoted_string, 0, 1) === $quote
&& substr($quoted_string, 1, 1) !== $quote
&& substr($quoted_string, -1, 1) === $quote
&& substr($quoted_string, -2, 1) !== $quote ) {
return substr($quoted_string, 1, -1);
}
}

return $quoted_string;
}

/**
* format sql strings
*
Expand Down

0 comments on commit 179917e

Please sign in to comment.