PHP Snippet: Slugify a string

This one has some extra stuff for German characters in it. Probably not needed because it’s covered by iconv, but whatever:

function slugify($str)
{
       $returnMe = strtotime(trim(@iconv('UTF-8', 'ASCII//TRANSLIT', $str)));

       foreach ([
              " " => "_",
              "/" => "-",
              "" => "",
              "." => "-",
              "ü" => "ue",
              "ö" => "oe",
              "ä" => "ae",
              "ß" => "ss",
              "&" => "+",
              '"' => "_"
       ] as $search => $replace)
       {
              $returnMe = str_replace($search, $replace, $returnMe);
       }

       return $returnMe;
    }

PHP Snippet: Check if code is running on a production environment

function isLive($liveTld = ".de")
{
       $homeUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']
       === 'on' ? "https" : "http")."://$_SERVER[HTTP_HOST]";

$returnMe = false;
if ( (!(strpos($homeUrl, ".local") !== false)) && (!(strpos($homeUrl, ".intra") !== false)) && (!(strpos($homeUrl, "stage") !== false)) && (!(strpos($homeUrl, "staging") !== false)) && (strpos($homeUrl, $liveTld) !== false) ) { $returnMe = true; }
return $returnMe; }

Get the clients IP address

$clientIpAdress = isset($_SERVER['HTTP_CLIENT_IP'])?$_SERVER['HTTP_CLIENT_IP']:isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR'];

Do *not* use this on it’s own for security purposes!