Home  >  Article  >  Backend Development  >  How to replace img tag attribute with regular php

How to replace img tag attribute with regular php

王林
王林Original
2020-07-20 18:00:102771browse

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.

How to replace img tag attribute with regular php

#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 = &#39;<center><img src="/uploads/images/20100516000.jpg" height="120" width="120"><br />PHP正则提取或更改图片img标记中的任意属性</center>&#39;;

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!

Statement:
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