Php检查URL的第一个字母是否小于G.

Hey guys Im looking to echo a list of links based on the URL of a website. I was wondering if you could create an if/else to echo different lists based on the first letter of the domain of a site. So basicly if the domain starts with any letter before G it would echo my first list, and if its any letter after G it would echo something else

<?php
$str = "glue";
if ($str < "g"){
    //do stuff
    echo("yup");
}

$str = "fluor";
if ($str < "g"){
    //do stuff
    echo("yup2");
}

for your case

<?php 
$url = parse_url($_GET['url']); 
$str = $url['host']; 
echo $str; 
if ($str < "g"){ 
    //do stuff 
    echo(" has first character lower than g"); 
} 
else{ 
     echo(" has not first character lower than g"); 
}

just an idea:

$range_array = range('A','F');

if(in_array($foo,$range_array){
...
}

Try this:

   $url = "http://www.gaa.com";
    $parseURL = parse_url($url);
    $host = str_replace("www.","", $parseURL['host']);
    if($host[0] <= "g") {
        //do something.. 
    }else {
        //...
    }

You can convert a character to its ascii-value using ord():

<?php 
    $ascii_value = ord($link[0]);
    if( $ascii_value >= 65 && $ascii_value < 72 ) echo 'Foo'; 
    else echo 'Bar'; 
?>

My RegEx solution:

/^[a-f].*/gim
<?php
$firstLetter = substr(strtoupper($your_url), 0, 1);
if(ord($firstLetter) >= 65 && ord($firstLetter) <= 71) {
    // ... first letter is an A, B, C etc. including G
}
else if (ord($firstLetter) >= 72 && ord($firstLetter) <= 90) {
    // ... first letter is H or a later character
}
else {
    // ... first letter is not a letter of the alphabet
}
?>