【问题标题】:Get only image url from phpbb post text仅从 phpbb 帖子文本中获取图像 url
【发布时间】:2015-04-23 09:24:41
【问题描述】:
由于 PHPBB 有自己的调用内联图像的方式,我有类似这样的 post_text
test content [img:32acu135]http://mywebsite.com.pk/wp-content/uploads/2012/10/some-thing-3.jpg[/img:32acu135]
在数据库中,
有什么方法可以调用内容中的第一张图片,可能是使用 preg_match_all 或 regex..
【问题讨论】:
标签:
php
regex
preg-match-all
phpbb
【解决方案1】:
我会选择像这样的正则表达式
\[img.+?\](.*)\[\/img.+?\]
并采取捕获组
php 示例
$re = "/\\[img.+?\\](.*)\\[\\/img.+?\\]/";
$str = "[img:32acu135]http://mywebsite.com.pk/wp-content/uploads/2012/10/some-thing-3.jpg[/img:32acu135]";
preg_match($re, $str, $matches);
print($matches[1]);
结果:
http://mywebsite.com.pk/wp-content/uploads/2012/10/some-thing-3.jpg