我已經在互聯網上找到這段代碼...我真的不知道PHP ... 能有人高科技我,pleaase即時通訊pleasee ..PHP的preg_match_all,WordPress的功能
<?php
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('<img.+src=[\'"]([^\'"]+)[\'"].*>', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
?>
如何更換<img.+src=[\'"]([^\'"]+)[\'"].*>
如果我想採取後 「=」 和 「]」 這個文本前字:
[image name=ubuntustudio-tribal-54]
or
[image name=office-tool]
or
[image name=car]
or
[image name=158]
我想輸出TAKE 「AZ或符號或數字」 AFTER THIS「=」,並在此之前,「]」
感謝
怎麼樣教你自己? – hek2mgl 2013-05-09 20:19:11
不知道我明白了。你的圖片是簡碼還是發生了什麼?爲什麼你會在post_content中用方括號包裝圖像?如果它是正確的HTML,我建議使用DOMDocument,而不是正則表達式。 – adeneo 2013-05-09 20:20:21
當我沒有能力做任務時,我僱用了一個。 – 2013-05-09 20:21:06