<pre>
<?php
// 替换图片的目录为统一路径
$string = "a<img src=\"a/b/x.png\">,Biao,<img src=\"uploads/y.jpg\">";
// /U为非贪婪,这种非贪婪,是从后面向前找,与+?有些区别
$pattern ="/<img src=\"(.*)\/(.+\\..+)\">/U";
$replacement = "<img src=\"__IMG_BASE__/$2\">";
$pattern ="/<img src=\"(.*)\/(.+\\..+)\">+?/"; // +?结果与上面的不一样
echo preg_replace($pattern, $replacement, $string);
// 找出所有的图片,图片名
$pattern ="/<img src=\"(.*)\/(.+\\..+)\">/U";
preg_match_all($pattern, $string, $images);
print_r($images);
// 输出图片名
foreach ($images[2] as $index => $imageName) {
echo "$imageName<br/>";
}
?>