Jump to content

[SOLVED] Determin wether string contains . . . .


the_oliver

Recommended Posts

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)

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/49192-solved-determin-wether-string-contains/
Share on other sites

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
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.