Created
September 22, 2011 10:28
-
-
Save muratpurc/1234497 to your computer and use it in GitHub Desktop.
PHP: Remove unwanted characters like < > " from passed path value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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('<', '>', '"', '<', '>', "'", '"', '`'); | |
foreach ($aMatch as $p => $v) { | |
$value = str_replace($v, $replaceWith, $value); | |
} | |
return $value; | |
} | |
################################################################################ | |
## Example | |
$path = '/"var</www/"'; | |
echo mp_getCleanPathVar($path); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment