How to replace alt with php regular expression

藏色散人
Release: 2023-03-13 19:56:01
Original
2300 people have browsed it

php正则实现替换alt的方法:1、创建一个PHP示例文件;2、获取需要替换的内容;3、通过“”正则实现替换即可。How to replace alt with php regular expression*?src=[\"|\'](.*?)[\"|\'].*?>

How to replace alt with php regular expression

本文操作环境:windows7系统、PHP7.1版、DELL G3电脑

php正则怎么实现替换alt?

php正则表达式提取img alt/title标签并替换

有时我们需要对富文本编辑器中的img标签进行必要的处理以满足网站自身的需要,

比如:

根据站点关键词对页面内img的alt标签设定关键词,以下为提取并替换alt/title标签内容的正则:

$title = "需要替换的内容..."
$pattern= "/<img.*?src=[\"|\&#39;](.*?)[\"|\&#39;].*?>/";
$replace = &#39;<img src="$1" alt="&#39;.$title.&#39;"title="&#39;.$title.&#39;">&#39;;
$html = preg_replace($patter, $replace, $content);
Copy after login

推荐学习:《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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template