Skip to content

Instantly share code, notes, and snippets.

@muratpurc
Created September 22, 2011 10:28
Show Gist options
  • Save muratpurc/1234497 to your computer and use it in GitHub Desktop.
Save muratpurc/1234497 to your computer and use it in GitHub Desktop.
PHP: Remove unwanted characters like < > " from passed path value
/**
* Removes unwanted characters like < > " from passed path value
*
* @param string $value The value to clean
* @param string $replaceWith The replacement (empty by default)
* @return string Cleaned path value
*/
function mp_getCleanPathVar($value, $replaceWith = '')
{
$value = (string) trim($value);
$aMatch = array('&lt;', '&gt;', '&quot;', '<', '>', "'", '"', '`');
foreach ($aMatch as $p => $v) {
$value = str_replace($v, $replaceWith, $value);
}
return $value;
}
################################################################################
## Example
$path = '/"var</www/&quot;';
echo mp_getCleanPathVar($path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment