Im Zahnarztportal jadento.de können Zahnärzte Ihre Praxis Social Media Kanäle hinterlegen.

Um Tippfehler zu vermeiden und verschiedene Eingaben gleichmäßig abzuspeichern, kannst du folgende Helper Funktion verwenden:
function convert_url_socialmedia( $url, $type ) {
    $host = '';
    $scheme = 'https://';
    if ( 'facebook' === $type ) {
        $host = 'facebook.com';
    }
    if ( 'instagram' === $type ) {
        $host = 'instagram.com';
    }
    if ( 'tiktok' === $type ) {
        $host = 'tiktok.com';
    }
    if ( 'twitter' === $type ) {
        $host = 'twitter.com';
    }
    if ( '' === trim($host) ) {
        return null;
    }
    $url = parse_url($url);
    if ( isset($url['path']) ) {
        $path = $url['path'];
        $path_explode = explode('/', $url['path']);
        if ( $host === $path_explode[0] || 'www.'.$host === $path_explode[0] || $scheme.'www.'.$host === $path_explode[0] ) {
            $path = $path_explode[1];
        }
        if ( substr( $path, 0, 1) === '@' || substr( $path, 0, 1) === '/' ) {
            $path = substr( $path, 1);
        }
        $url = $scheme.$host.'/'.$path;
        if ( '' !== trim($url) ) {
            return $url;
        }
    }
    return null;
    
}
Deine User können nun
- https://facebook.com/username
 - https://www.facebook.com/username
 - www.facebook.com/username
 - @username
 - /username
 - username
 
eingeben der Output ist aber immer der gleiche: https://facebook.com/username