2013-04-18 170 views
0

我想這個轉換(從WordPress的)轉換標題標籤圖標籤

[caption id="attachment_5433" align="aligncenter" width="413"] 
    <a href="http://baicadicungnamthang.net/uploads/2012/02/NSUT-Tuyet-Thanh.jpg"><img class=" wp-image-5433" title="NSUT-Tuyet-Thanh" src="http://baicadicungnamthang.net/uploads/2012/02/NSUT-Tuyet-Thanh.jpg" alt="NSƯT Tuyết Thanh" width="413" height="551"></a>NSƯT Tuyết Thanh 
[/caption] 

這樣:(HTML5)

<figure> 
    <a href="http://baicadicungnamthang.net/uploads/2012/02/NSUT-Tuyet-Thanh.jpg"><img class=" wp-image-5433" title="NSUT-Tuyet-Thanh" src="http://baicadicungnamthang.net/uploads/2012/02/NSUT-Tuyet-Thanh.jpg" alt="NSƯT Tuyết Thanh" width="413" height="551"></a> 
    <figcaption>NSUT Tuyết Thanh</figcaption> 
</figure> 

如何通過PHP或C#做呢?

+2

://開頭抄本。 wordpress.org/Function_Reference/add_shortcode)文檔。 – Emissary

+0

這與您關於標題中圖像的其他問題是一致的) – 2013-04-18 10:42:49

回答

0

試試這個:

$subject = preg_replace(
'/\[caption[\s]{0,}(.*?)\][\s]{0,}(<a[\s]{0,}.*?<\/a>)[\s]{0,}(.*?)\[\/caption\]/ims', 
'<figure $1> $2 <figcaption>$3</figcaption> </figure>', 
$subject); 

其中$受試者患有通過讀取[`add_shortcode`(HTTP的[標題]實際字符串[/字幕]

+0

經過測試並正常工作。 –