PHP文件()到foreach数组并进入img

I have been trying to convert to images the results from a list produced by file() an by file_get_contents and I have got this far but cant seem to be getting any where: Here's what I got:

<?php
$data = file('http://cadenanoticias.com.mx/galerias/notas/22925/');

foreach((array)$data as $whoisline){
echo '<img src="http://cadenanoticias.com.mx/galerias/notas/22925/'.$whoisline.'">';
}
?>

So far I can see the ending double quotes and the closing bracket and that's it.

Any Idea on how to achieve this?

With a little help of PHP Simple HTML DOM Parser you could just do the following.

<?php
require "simple_html_dom.php";

// Create DOM from URL or file
$html = file_get_html("http://cadenanoticias.com.mx/galerias/notas/22925/");

// Find all images
foreach($html->find("a") as $element) {
    if (substr(strrchr($element->href,'.'),1) == "jpg") {
        echo '<img src="http://cadenanoticias.com.mx/galerias/notas/22925/'. $element->href .'">';
    }
}

You need to look into glob.

foreach (glob("/galerias/notas/22925/*.{png,jpg,tiff}") as $filename) {

echo '<img src="http://cadenanoticias.com.mx/galerias/notas/22925/'.$filename.'">';

}

The data returned in your example using file_get_contents is HTML, so in order to extract the images you'll have to parse the HTML.

I would recommend using curl instead to fetch the HTML as file_get_contents doesn't always allow fetching of remote URLs.

Another option is to use preg_match to extract the image URLs and then you can loop through them as desired.

If the directory is local, then you could use glob and then the data returned will be an array that you can loop through.

ok my idea for what it is worth:

on the http://cadenanoticias.com.mx/galerias/notas/22925/ site add an index.php:

<?php
$files=array();
foreach (glob("*.jpg") as $filename) {
$files[]=$filename;
}
echo json_encode($files);

on the script on the other server

<?php
    $data = file_get_contents('http://cadenanoticias.com.mx/galerias/notas/22925/');

    foreach(json_decode($data) as $myImage){
    echo '<img src="http://cadenanoticias.com.mx/galerias/notas/22925/'.$myImage.'">';
    }
    ?>