怎麼讀取<img>裡的title

來源:互聯網
上載者:User
如何讀取裡的title
在下面的函數中,讀取了src,請問如何再讀取裡的title
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;
}
------解決思路----------------------
如果不確定是否每張圖都有title標記,需要二次正則擷取。
修改如下:

function get_pic_list($content='')
{
$pattern="/------解決思路----------------------
\"](.*?(?:[\.gif
------解決思路----------------------
\.jpg]))[\'
------解決思路----------------------
\"].*?>/";
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], $match1);
$arr_pic[$i]['title'] = isset($match1[1])? $match1[1] : '';
}
return $arr_pic;
}

$content =<<


管理菜單



TXT;

$result = get_pic_list($content);

print_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] =>
)

)
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.