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?
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;