嗨,我正在開發一個自定義論壇,在我的網站上。我想將網址轉換爲:http://*.domain.com/photos/ {用戶名}/{photo_id}(我應該同時獲取用戶名和photo_id)到直接圖片代碼,以便用戶獲取圖片的網址。解析bbcode中的url
這應該,如果他們把這個網址有或沒有設置高亮來完成:
即:
http://domain.com/photos/musthafa/12345
[URL = HTTP://domain.com/photos/musthafa/12345]我的照片此處鏈接[/ URL]
[URL = HTTP://domain.com/photos/musthafa/12345] http://domain.com/photos/musthafa/12345 [/ URL]
這應被轉換爲< HTML- imge tag src =「url-to_photo-path/photo_id.j_p_g」/>
我試過這個:
$str = "http://www.domain.com/photos/musthafa/12345"
$str = preg_replace_callback("'\[url=http:\/\/www\.domain\.com\/photos\/(.*?)\](.*?)\[/url\]'i", 'self::parse_photo_url', $str);
AND
$str = preg_replace_callback("#^https?://([a-z0-9-]+\.)domain.com/photos/(.*?)$#", 'self::parse_gpp_photo', $str);
function parse_photo_url($url){
{
$full_url = "http://www.domain.com/" . $url[1];
$url_segs = parse_url($full_url);
$path = explode("/", $url_segs['path']);
return '<img src="http://www.domain.com/{path-to-the-gallery}/'.$path[2].'/jpg" />';
}