Support » Developing with WordPress » Sanitizing server name

  • Resolved Guido



    I’m using $_SERVER['SERVER_NAME'] in my script to build a FROM email header.

    I want to sanitize the value before using it, but having difficulties finding the proper function for that. I want to get the URL without http:// or https://.

    Without sanitizing it will output the way I want:

    $domain = $_SERVER['SERVER_NAME'];

    This will output the full URL:

    $domain = esc_url_raw($_SERVER['SERVER_NAME']);

    This will strip the . characters from the URL:

    $domain = sanitize_key($_SERVER['SERVER_NAME']);

    I prefer using a native PHP/WP function instead of using extra functions to alter my output, such as substr().

    Any thoughts?


Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.