1,105,352 Community Members

Wildcard in variable

Member Avatar
Clarkeez
Light Poster
26 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
joshmac
Junior Poster
119 posts since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
1
 

You may need to use domain matching to acheive your goal because I don't think it will work that way. Check out this post: http://stackoverflow.com/questions/4278564/regex-to-match-subdomains-other-than-www

Member Avatar
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 85 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: