Regular expression - PHP regular batch replacement of src in Img question?

WBOY
Release: 2016-08-22 11:45:37
Original
1528 people have browsed it

1. A description content, in the form of:




2. Now my requirement is to batch replace the image paths in src. I can change the path to /upload/img/. How do I write the regular change?

Reply content:

1. A description content, in the form of:




2. Now my requirement is to batch replace the image paths in src. I can change the path to /upload/img/. How do I write the regular change?

str_replace('file:///C:/Users/Administrator/Desktop/test/data/5201608091357/contentPic/ linen skirt 16/','/upload/img/',$str)

1. Because your prefix is fixed, it is actually more efficient to use str_replace.
2. If it is not fixed, you can refer to the following methodpreg_replace_callback
3. When debugging, remember to view the source code.




'; echo $str; $pregRule = "/file:\/\/\/C:\/Users\/Administrator\/Desktop\/测试\/data\/5201608091357\/contentPic\//"; $result = preg_replace_callback($pregRule, function(){ return "/upload/img/"; }, $str); echo $result;
Copy after login
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!