我希望$_POST['textarea']
内的IMG标记改为:
示例:
$_POST['textarea'] = <b>Some example Text</b><br> <img src="image_1.jpg" alt="bla bla" width="250" height="100" /> <u>some more text</u><br> <img src="image_2.jpg" alt="bla bla" width="50" height="20" />
采用以下格式:
$final = <b>Some example Text</b> <a class="fancybox" rel="gallery1" href="image_1.jpg" title="bla bla"><img src="image_1.jpg" alt="bla bla" width="250" height="100" /></a> </u>some more text</u> <img src="image_2.jpg" alt="bla bla" width="50" height="20" />
答案 0 :(得分:0)
在您的信息页中加入simple_html_dom.php。从http://en.sourceforge.jp/projects/sfnet_simplehtmldom/downloads/simplehtmldom/1.10/simplehtmldom_1_10.zip/
下载 <?php
require_once('controller/simple_html_dom.php');
$str = 'Some example Text <img src="image_1.jpg" alt="bla bla" width="250" height="100" />
some more text <img src="image_2.jpg" alt="bla bla" width="50" height="20" />';
$html = str_get_html($str);
$img = array();
foreach ($html->find('img') as $images) {
if($images->getAttribute('width') > 50) {
$img[] = '<a class="fancybox" rel="gallery1" href="'.$images->getAttribute('src').'" title="bla bla">'.$images.'</a>';
} else {
$img[] = $images;
}
}
$full = '';
$i = 0;
foreach ($html->find('text') as $text) {
$full .= $text.$img[$i];
$i++;
}
echo $full;
?>