johnsmith153 Posted July 8, 2010 Share Posted July 8, 2010 I have a PHP string which was created from a JavaScript text editor in a browser. If they enter nothing the string is empty. If they enter lots of text, I will obviously see this in the PHP string. However, if they enter just line breaks or press the enter button and no text then I will get something like: $val = "<p> </p><br />" etc... How can I search to see if a string only contains: <p> </p> \r \n <br/> If it ONLY contains these I can then just store a blank value in the database and not all the <p> and <br /> tags etc. Link to comment https://forums.phpfreaks.com/topic/207152-search-for-certain-values-in-php-string/ Share on other sites More sharing options...
ChemicalBliss Posted July 8, 2010 Share Posted July 8, 2010 You should never allow HTML to be input directly from a user. (htmlentities($input) to get rid of any html/javascript) What you would do, is check whether there are any valid characters (a-z, 0-9), you can do this with a very simple preg match: if(!preg_match("/[a-z0-9]+/i",$input)){ // This very simple preg checks whether there is at least 1 or more letters, or numbers (a Single number/character would pass this check). echo("Error, please enter valid data"); } You can use much more complex queries to further sanitize your inputs. -cb- Link to comment https://forums.phpfreaks.com/topic/207152-search-for-certain-values-in-php-string/#findComment-1083136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.