jepler Posted February 6, 2007 Share Posted February 6, 2007 Hello, I'm trying to match a pattern that starts with the letters "tn" but could have a variety of characters after. I tried the following but it doesn't seem to work: if (preg_match("^tn%",$myword)) { do something... Quote Link to comment Share on other sites More sharing options...
Tyche Posted February 6, 2007 Share Posted February 6, 2007 You need to put your Regex Pattern in delimiters, try if (preg_match("/^tn%/",$myword)) { do something... Or use strpos - it's a bit more efficient in this case e.g. if (strpos($myword,"tn")===0) { do something... Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 6, 2007 Share Posted February 6, 2007 Remove the % sign as well: if (preg_match("/^tn/", $myword)) Quote Link to comment Share on other sites More sharing options...
jepler Posted February 7, 2007 Author Share Posted February 7, 2007 excellent! thanks!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.