How to replace src in php

藏色散人
Release: 2023-03-07 21:28:02
Original
2605 people have browsed it

How to replace src in php: First create a PHP sample file; then use the "preg_replace_call" function to replace src in the image img, with statements such as "str_replace($ma[1],lsk::picurl($ ma[1]),$ma[0]);".

How to replace src in php

Recommended: "PHP Video Tutorial"

The operating environment of this tutorial: Windows 7 system, PHP version 5.6, Dell G3 computer.

php replaces the image src address in the text string in turn

For example, there is a piece of code like this:

<p><img _src="/tt.jpg" src="http://www.sjmoban.com/tt.jpg" title="1539765170791397.jpg"/></p>
Copy after login

I want to add the image img If the src is replaced by the address processed by a specific function, you can use the preg_replace_call function to operate. The code is as follows:

$pattern="/<[img|IMG].*?src=[\&#39;|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg]))[\&#39;|\"].*?[\/]?>/i";
preg_replace_callback($pattern,function($ma) {
    return str_replace($ma[1],lsk::picurl($ma[1]),$ma[0]);
},$content);
Copy after login

Midterm:lsk::picurl()//This function processes the src address.

The above is the detailed content of How to replace src in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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