Copy Code code as follows:
reg =/<[img|href][^>]*src\s*=\s* (' | ')? ([^ ' ">]*) \1 ([^>]) *>/ig
Regular Get Picture address
First, the question:
Acquisition of the process encountered a problem: from the database read out of the picture is not normal display, analysis found that the database is the image of the site as a relative path to the root directory storage, picture address such as:/uploads/allimg/090403/ 012f31n9-1.jpg, the original do read the image is http://switch url absolute image acquisition, so the acquisition of the root directory to start the image address collection failed.
Second, the solution:
Analyze HTML code, display picture set tag, write a regular access to the picture address in and add the site to the URL of the site to the absolute address, and then to the following things to the next code (remote image Acquisition to local).
1 Improve the solution to "2) Emergency solutions, as long as the "src=" attribute to start the regular formula, but this way there are imperfections, as long as there are "src=" will be replaced, there are "src=" possibility: JavaScript, the text appears in the "src" and so on. But these are relatively few, plus a picture format to do the regular limit, there will be less chance of being mistakenly replaced.
Third, the implementation code:
Considering the difficulty of the first method is not written for the time being, here is the second kind of emergency solution implementation (implementation of the regular content involved here does not do the explanation and analysis, the regular type of knowledge content please Google or Baidu ^v^):
Copy Code code as follows:
<?php
Test the style, taking into account the regular formula in many cases.
$body = <<<p align=center>1</P>
<p align=center>2</P>
<p align=center>3 </P>
<p align=center>4</P>
<p align=center>5</P>
<p align=center>6</P>
<p align=center>7 </P>
HTML;
The address of the website
$str = ' src=/' http://www.chongwen.com/';
$body =preg_replace ('/src/s*?=/s*?[ /"|/']?/s*?//" (. +?/. (?: jpg|gif|png|bmp)) (/"|/' |/s) *?/s*?/is '", "$str $", $body);
Echo $body;
?>