嗨,我正在开发一个自定义论坛,在我的网站上。我想将网址转换为: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" />';
}