试图提出一个 PHP 正则表达式来提取文本中第一个 [img]...[/img] 标记的内容。也可以是 img 或 IMG。
非常感谢任何帮助。
使用我糟糕的正则表达式,我得到了以下内容,但它不起作用:
/[img](.+)[/img/]
下面是一个应该起作用的文本示例:http://pt.wikipedia.org/wiki/Erich_von_D%C3%A4niken]Erich Von Daniken[/url][/align] [align=center][img]http:/ /www.ceticismoaberto.com/wp-content/uploads/2012/04/erich_von_daniken_7.jpg[/img]
它应该只返回: http ://www.ceticismoaberto.com/wp-content/uploads/2012/04/erich_von_daniken_7.jpg
我正在使用网页向正则表达式发送文本: http ://www.myregextester.com/index.php 我正在使用 的 PHP 代码是:
$message=$post["message"];
//try to locate the first image on the post text
if (preg_match("!http://[^?#]+\.(?:jpe?g|png|gif)!Ui", $message, $matches)) {
return $matches[0];
}
上面的正则表达式在某些情况下不起作用,就像我之前展示的那样,这就是我尝试不同方法的原因。