The IMG tag of the collected image contains a lot of JavaScript scripts and useless information. You must replace what you want, such as alt. Let's take a look at the content to be filtered. I just copied it:
CopyCode Code: sdfsdfsdf 500) {This. resized = true; this. style. width = 500;} "> sfsdfsdfasdfsadf 500) {This. resized = true; this. style. width = 500;} "> sdfsadf 500) {This. resized = true; this. style. width = 500;} "> sdfsdf
The above should be replaced and formed as follows:Copy codeThe Code is as follows: where src = "http://www.xxx.com/upimg/080330/120d1232295023x0.gif" src = "http://www.xxx.com/upimg/080330/others "This address must be retained, because the image uses the source address.
The general method is: first read the IMG label in the content, then extract the SRC of each IMG label, combine it into its own content, and finally replace it.
Preg_match_all is the function I want. It can create a three-dimensional array of the content matched by the regular expression. You can traverse and search for them and replace them. If you are not familiar with it, please refer to the manual, I will not introduce it here. Function Code:Copy codeThe Code is as follows: function Replace ($ Str)
{
Preg_match_all ("/] +>/ISU", $ STR, $ ARR );
For ($ I = 0, $ J = count ($ arr [0]); $ I <$ J; $ I ++ ){
$ STR = str_replace ($ arr [0] [$ I], "}
Return $ STR;
}