我試圖用適當的HTML標籤和有麻煩瞄準只是普通鏈接IM更換圖片鏈接,YouTube視頻鏈接和常規鏈接分開: 這裏是我的代碼:我如何捕獲這個正則表達式的鏈接?
function($text)
{
$output = preg_replace('#(http://([^\s]*)\.(jpg|gif|png))#',
'<br/><img src="$1" alt="" width="300px" style = "clear:both;"/><br/>', $text);
$output = preg_replace('#(http://([^\s]*)youtube\.com/watch\?v=([^\s]*))#',
'<br/><iframe width="480px" height="385px" src="http://www.youtube.com/embed/$3"
frameborder="0" allowfullscreen style = "clear:both;"></iframe><br/>', $output);
$output = preg_replace('#(http://([^\s]*)\.(com))#',
'<br/><a href="$1">$1</a><br/>', $output);
return $output
}
這不是取代中的所有鏈接最後一步......我如何避免這種情況,並在最後一步中只替換鏈接(不是youtubes或圖像)?
謝謝!
可能重複http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Amber
與該鏈接imo無關... – algorithmicCoder