How to read the title in <img>

Source: Internet
Author: User
In the function below, read SRC, how can I read the title in the
function get_pic_list ($content = ")
{
$pattern = "//";
Preg_match_all ($pattern, $content, $match);

$arr _pic = Array ();
$i = 0;
foreach ($match [1] as $IMGSRC)
{
$arr _pic[$i [' src '] = $imgsrc;
$i + +;
}

return $arr _pic;
}


Reply to discussion (solution)

See if it does.

function get_pic_list ($content = ") {    $pattern ="//";     Preg_match_all ($pattern, $content, $match);     $arr _pic = Array ();    $i = 0;    For ($i =0, $len =count ($match [1]), $i < $len, $i + +) {        $arr _pic[$i] [' src '] = $match [1][$i];        $arr _pic[$i [' title '] = $match [2][$i];    }    return $arr _pic;} $content =<<
 <> 
    admin menu txt; $result = get_pic_list ($content);p rint_r ($result);
 


Array (    [0] = = Array        (            [src] =/assets/ico_set.gif            [title] = Title1        )    [1] = > Array        (            [src] =/assets/arrow_down.gif            [title] = Title2        ))

After the call, the display is not correct, I originally uploaded a lot of pictures, but only show two, and show these two I use to view the source, the title value is empty.

In the following call page JS is not also to make changes?? How to change??



{foreach from= $album _list item=pic}



{/foreach}

Do you have a title tag for each picture? And the title is placed behind Src.

may not be the case of JS, because I deleted that section of JS, but also only show two pictures without the title value

Not every title, some have, some not

Add title to try. No, plus title= ""

Just added, also only show a part, I tried, respectively, the value of the title is set to 1,2,3,4,5,6,7,8, but only show the 2,4,6,8

is to show a single

If you are unsure whether each picture has a title tag, two regular fetches are required.
Modify the following:

function get_pic_list ($content = ") {    $pattern ="//";     Preg_match_all ($pattern, $content, $match);     $arr _pic = Array ();    $i = 0;    For ($i =0, $len =count ($match [1]), $i < $len, $i + +) {        $arr _pic[$i] [' src '] = $match [1][$i];        Preg_match ('/title=[\ ' |\ "] (. *?) [\ ' |\ ']/', $match [0][$i], $match 1);        $arr _pic[$i [' title '] = Isset ($match 1[1])? $match 1[1]: ';    }    return $arr _pic;} $content =<<
 <> 
    admin menu  TXT; $result = Get_pic_list ($content);p rint_r ($result);
 


Array (    [0] = = Array        (            [src] =/assets/ico_set.gif            [title] = Title1        )    [1] = > Array        (            [src] =/assets/arrow_down.gif            [title] = Title2        )    [2] = = Array        (            [src] =/assets/arrow_down123.gif            [title] =)         )

If you still have a problem, you can send $content out to see.

Yes, thank you.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.