ShoeLace1291 Posted June 28, 2007 Share Posted June 28, 2007 I was wondering how I would be able to keep users from putting certain characters such as <,>,\,/?, etc in text inputs in forms? Link to comment https://forums.phpfreaks.com/topic/57510-restricting-certain-characters-from-input/ Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 if(ereg('(\<(/?[^\>]+)\>)',$string)) { action here } i think its something like that Link to comment https://forums.phpfreaks.com/topic/57510-restricting-certain-characters-from-input/#findComment-284553 Share on other sites More sharing options...
JasonLewis Posted June 28, 2007 Share Posted June 28, 2007 i think you could use htmlentities or one of those functions. http://au.php.net/manual/en/function.htmlentities.php that allows them to enter them but it makes them non-html... Link to comment https://forums.phpfreaks.com/topic/57510-restricting-certain-characters-from-input/#findComment-284555 Share on other sites More sharing options...
ShoeLace1291 Posted June 28, 2007 Author Share Posted June 28, 2007 So if I used htmlentities($_POST['username']); what would that do? Link to comment https://forums.phpfreaks.com/topic/57510-restricting-certain-characters-from-input/#findComment-284559 Share on other sites More sharing options...
JasonLewis Posted June 28, 2007 Share Posted June 28, 2007 did you read the manual? lol... that would help... taken from manual: $str = "A 'quote' is <b>bold</b>"; // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str); // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str, ENT_QUOTES); ?> basically. it would appear as it as written. so if you were to write a link, it would appear as the html and not as the link. i think that makes sense. lol. the < b > tags would appear as that on the screen. so they wouldnt work in making the text bold. Link to comment https://forums.phpfreaks.com/topic/57510-restricting-certain-characters-from-input/#findComment-284562 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 if(ereg('[\<+|\>+|\\+|\/+|\?]',$string)) { echo 'mali'; } that wont accepr ?<>/\ Link to comment https://forums.phpfreaks.com/topic/57510-restricting-certain-characters-from-input/#findComment-284568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.