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]);".
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:
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=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg]))[\'|\"].*?[\/]?>/i"; preg_replace_callback($pattern,function($ma) { return str_replace($ma[1],lsk::picurl($ma[1]),$ma[0]); },$content);
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!