Home > Article > Backend Development > How to replace img tag attribute with regular php
The way PHP regularly replaces the img tag attribute is through the preg_match() function. This function is used to perform a regular expression match and return the number of matches. The preg_match() function stops the search after the first match.
#We can achieve this through the preg_match() function.
(Recommended tutorial: php tutorial)
Function introduction:
preg_match function is used to perform a regular expression matching.
Function syntax:
int preg_match( string $pattern ,string $subject [,array &$matches [,int $flags = 0 [,int $offset = 0]]] )
Return value:
Returns the number of matches of pattern. Its value will be 0 (no match) or 1 because preg_match() will stop searching after the first match. preg_match_all() differs from this in that it searches for the subject until it reaches the end. If an error occurs preg_match() returns FALSE.
Code implementation:
<?php /*PHP正则提取图片img标记中的任意属性*/ $str = '<center><img src="/uploads/images/20100516000.jpg" height="120" width="120"><br />PHP正则提取或更改图片img标记中的任意属性</center>';
The above is the detailed content of How to replace img tag attribute with regular php. For more information, please follow other related articles on the PHP Chinese website!