2011-08-09 3 views
2

私はテキストを含む文字列を持っており、画像リンクをimgタグやその他のタグへのリンクに置き換えたいと考えています。Preg_replace URLと画像をPHPで

私はすでにやったこと:

$row['message'] = preg_replace('/(http:\\/\\/.+(png|jpeg|jpg|gif|bmp))/Ui', '<img height="'.self::getConfig('image_height').'" src="$1" />', $row['message'], -1, $countImages); 

$row['message']内のタグにタグをIMGの以外のすべてのリンクを交換する方法は?

Thanx!

答えて

0

URLがsrc="に続くかどうかを確認するには、正規表現に否定的な検索ビヘイビアを追加します。

$row['message'] = preg_replace('/(?<!src=")(http:\\/\\/.+(png|jpeg|jpg|gif|bmp))/Ui', '<img height="'.self::getConfig('image_height').'" src="$1" />', $row['message'], -1, $countImages);