Problem with a PHP Function search links

2

I have a problem with this works what I want to do is the following I want to look for the data of the link but not to give me an error information along with the correct one and if there is no data I get an error message

    function External_links($Link_info){


        $content = '
            "url_line":"/youtube.com(.+)v=([^&]+)/";
            "url_line":"/vimeo.com\/([a-z1-9.-_]+)/";
            "url_line":"/facebook.com\/[a-z1-9.-_]+/";
        ';

        if (preg_match_all('#"url_line":[^"]*"([^"]*)"#', $content, $resultado)) {
            $mp = $resultado[1];   
        } else {
            $mp = ['sin coincidencias']; // este mensaje de error
        }

        foreach ($mp as $nombre) {
            if(isset($Link_info)) :
            $url = $Link_info;



                if(preg_match($nombre, $url)) {
            //=== youtube information generator 
                    echo 'yes <br>';
                }else{
                    //-- Error 404
                    echo 'no funciona <br>';
                } 

            endif;///
        }
    }

echo External_links('https://www.youtube.com/watch?v=OawLX0jVRVU');
    
asked by sode 23.08.2018 в 23:23
source

1 answer

1

What you can do is create a variable that contains the result and change if it finds the url. Something like this:

<?php
function External_links($Link_info){

        $content = '
            "url_line":"/youtube.com(.+)v=([^&]+)/";
            "url_line":"/vimeo.com\/([a-z1-9.-_]+)/";
            "url_line":"/facebook.com\/[a-z1-9.-_]+/";
        ';

        if (preg_match_all('#"url_line":[^"]*"([^"]*)"#', $content, $resultado)) {
            $mp = $resultado[1];   
        } else {
            $mp = ['sin coincidencias']; // este mensaje de error
        }
        $result = 'no funciona <br>';
        foreach ($mp as $nombre) {
            if(isset($Link_info)) :
                $url = $Link_info;    

                if(preg_match($nombre, $url)) {                
                    $result = 'yes <br>';
                }

            endif;///
        }
        return $result;
    }

echo External_links('https://www.youtube.com/watch?v=OawLX0jVRVU');

?>
    
answered by 23.08.2018 / 23:50
source