unidox Posted January 19, 2009 Share Posted January 19, 2009 I am trying to use if preg_match but I am not to good at regex. I was wondering how I can do this: I have a form and the name of an input is username_required, I am trying to check to see if _required is in the name. How do I do that? Thanks Link to comment https://forums.phpfreaks.com/topic/141526-search-string/ Share on other sites More sharing options...
DarkWater Posted January 19, 2009 Share Posted January 19, 2009 You don't need regex for this. <?php $field_name = "username_required"; if (strpos($field_name, "_required") !== FALSE) { //it's there } else { //nope } Link to comment https://forums.phpfreaks.com/topic/141526-search-string/#findComment-740796 Share on other sites More sharing options...
MadTechie Posted January 20, 2009 Share Posted January 20, 2009 DarkWater's is better as it uses less resource but.. if you wanted a regex to check if it ended with "_required" then the below would work if (preg_match('/_required$/i', $field_name)) { //it's there } Link to comment https://forums.phpfreaks.com/topic/141526-search-string/#findComment-740817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.