0

Here is my regex to get the image url on the page.

<?php       
        $url = $_POST['url'];       
        $data = file_get_contents($url);    
        $logo = get_logo($data);
        function get_logo($html) 
            {
                preg_match_all('/\bhttps?:\/\/\S+(?:png|jpg)\b/', $html, $matches);
                //echo "mactch : $matches[0][0]";
                return $matches[0][0];  
            }

?>

Is there any thing missing in regex? for some of the url it does not give image url though they have image in it.

for example: http://www.milanart.in/

it does not give image on that page.

Please No dome. I could not use it.

1

2 Answers 2

1
<?php       
    $url = "http://www.milanart.in";       
    $data = file_get_contents($url);  
    $logo = get_logo($data);

    function get_logo($html) 
        {
            preg_match_all("/<img src=\"(.*?)\"/", $html, $matches);
            return $matches[1][0];  
        }
    echo 'logo path : '.$logo;
    echo '<img src="'.$url.'/'.$logo.'" />';
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but this sulution does not work for all case. Regex should be such that it should independantly scrap image url. check your above code for 'metacritic.com/movie/…'
It's an example who work with one solution, you can return an array with all response and check if the string have an 'http' or no ... You need to adapt your code
1

Use DOM Class of PHP to get all images:

  1. Search for image files in CSS.....url(imagefilename.extension)
  2. Search for image file in HTML ......

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.