1.11M Members

Wildcard in variable

 
0
 

Hello

I'm not sure how this is possible but I want to enter a wildcard(?) into a php variable..

like this,

<?php
  if($_SERVER['HTTP_HOST'] == '*.domain.com') {
    //do something
  }
?>

Notice the *
I basically need it to match if its any subdomain of domain.com

Possible?

 
1
 

could use strlen and strpos to do that:

<?php
echo "strlen(\$_SERVER['HTTP_HOST']): ".strlen($_SERVER['HTTP_HOST'])."<br/>\r\n";
echo "strlen(\$_SERVER['HTTP_HOST']): ".strlen($_SERVER['HTTP_HOST'])."<br/>\r\n";
echo "strpos(\$_SERVER['HTTP_HOST'],'.domain.com'): ".strpos($_SERVER['HTTP_HOST'],'.domain.com')."<br/>\r\n";
echo "strlen(strpos(\$_SERVER['HTTP_HOST'],'.domain.com')): ".strlen('.domain.com')."<br/>\r\n";

if(strlen($_SERVER['HTTP_HOST']) == (strpos($_SERVER['HTTP_HOST'],'.domain.com') + strlen('.domain.com'))){
    echo "String ends: .domain.com<br/>\r\n";
}
?>

strpos might need +1 or -1 , it might miss a character off the count. Basically the first echoed number should equal the 2nd + 3rd

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: