the_oliver Posted April 29, 2007 Share Posted April 29, 2007 Hello, Im trying to get an if statment to do veraies things depandin on the pattern of the strings contents. Eg: If the sting is in the format "number.number.number.number", (where the only fixed factor is the number of .'s) then do this: (somestuff) If the last 10 charictors of string are "domain.tld" then do this: (somestuff) Else do this: (somestuff) Can anyone sugges how to look for the patterns? Thanks! (The resion behind it is that i need to be able to translate host-abreviations into there domain name, or ip address, and visa-versa! All that needs to be done from a simple function which is fed the current value. and whats wanted back. It needs to be able to determin what the current value type is for its self) Quote Link to comment https://forums.phpfreaks.com/topic/49192-solved-determin-wether-string-contains/ Share on other sites More sharing options...
toplay Posted April 29, 2007 Share Posted April 29, 2007 Try something like this: <?php if (preg_match('/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/', $data)) { // IP address match } else if (preg_match('/[a-z]{6}\\.[a-z]{3}$/i', $data)) { // Has six letters, a period, then three letters at the end } else { // Something else } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49192-solved-determin-wether-string-contains/#findComment-241047 Share on other sites More sharing options...
the_oliver Posted April 29, 2007 Author Share Posted April 29, 2007 Fantastic. No wonder tring to write it gave me a headach!! Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49192-solved-determin-wether-string-contains/#findComment-241049 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.