" regular replacement can be achieved."/> " regular replacement can be achieved.">
Home >Backend Development >PHP Problem >How to replace alt with php regular expression
php正则实现替换alt的方法:1、创建一个PHP示例文件;2、获取需要替换的内容;3、通过“3ff66012414d143c4db21d46a3b5be17”正则实现替换即可。*?src=[\"|\'](.*?)[\"|\'].*?>
本文操作环境:windows7系统、PHP7.1版、DELL G3电脑
php正则怎么实现替换alt?
php正则表达式提取img alt/title标签并替换
有时我们需要对富文本编辑器中的img标签进行必要的处理以满足网站自身的需要,
比如:
根据站点关键词对页面内img的alt标签设定关键词,以下为提取并替换alt/title标签内容的正则:
$title = "需要替换的内容..." $pattern= "/<img.*?src=[\"|\'](.*?)[\"|\'].*?>/"; $replace = '<img src="$1" alt="'.$title.'"title="'.$title.'">'; $html = preg_replace($patter, $replace, $content);
推荐学习:《PHP视频教程》
The above is the detailed content of How to replace alt with php regular expression. For more information, please follow other related articles on the PHP Chinese website!