隔离要修改的图像
我有一个包含文本和图像的富文本字段(称为描述),
我尝试隔离所有图像以修改 src 标记以在
示例之前和之后添加元素: 应该变成
我成功了当我的领域中只有一张图像时,我使用这个:
$descriptionencodee = utf8_encode($description);
$parser = xml_parser_create();
xml_parse_into_struct($parser, $descriptionencodee, $values);
foreach ($values as $key => $val) {
if ($val['tag'] == 'IMG') {
$first_src = $val['attributes']['SRC'];
break;
}
$string = $description;
$replacement = '<img src="'timthumb.php?src='. $first_src .'&h=50" />';
// $replacement = '${1}<br/>';
$string = preg_replace("/(\<img\b[^>]*>)/", $remplacement, $string);
echo $string;
所以当有多个图像时它不起作用
I have a rich text field (called description) which containing texts and images
I try to isolate all the images to modify the src tag to add elements before and after
example : <img src="path/to/myimage.jpg" />
should become <img src="timthumb.php1src=path/to/myimage.jpg&h=50" />
I succeed when there's just one image in my field, i use this :
$descriptionencodee = utf8_encode($description);
$parser = xml_parser_create();
xml_parse_into_struct($parser, $descriptionencodee, $values);
foreach ($values as $key => $val) {
if ($val['tag'] == 'IMG') {
$first_src = $val['attributes']['SRC'];
break;
}
$string = $description;
$replacement = '<img src="'timthumb.php?src='. $first_src .'&h=50" />';
// $replacement = '${1}<br/>';
$string = preg_replace("/(\<img\b[^>]*>)/", $remplacement, $string);
echo $string;
so it doesn't work when there's more than one image
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在我最近的一个项目中很有用:
This worked for me in a recent project: