Jump to content

[SOLVED] Determin wether string contains . . . .


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
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.