Php is used to process all img tags in a piece of html code. there is a piece of html code that contains many tags and a lot of img tags. now, you need to extract the src Image addresses of all img tags in php language, and process them through a program to generate the image addresses under your server, replace the original src Image address with the address processed by our program. Make sure that all img tags in html code are processed by php in the image.
There is an html code that contains many tags and many img tags. now, you need to extract the src Image addresses of all img tags in php, after some program processing, the image address under my server is generated, and the original src Image address is replaced with the address processed by my program.
Make sure that the img tag after the image address is replaced is the same as the original img tag in the html code.
Php html image sharing:
------ Solution --------------------
This can be implemented using regular expressions.
$ Url = "http://www.ggggggg.com ";
// The file_get_contents () function reads the entire file into a string.
$ String = file_get_contents ($ url );
// The preg_match_all function matches the global regular expression.
Preg_match_all ("/] *) \ s * src = ('
------ Solution --------------------
\ ") ([^ '\"] + )('
------ Solution --------------------
\")/",
$ String, $ matches); // enclosed by quotation marks
// Preg_match_all ("/] *) \ ssrc = ([^ \ s>] +)/", $ string, $ matches); // no quotation marks
$ New_arr = array_unique ($ matches [0]); // Remove repeated values from the array
Foreach ($ new_arr as $ key ){
Echo $ key ."
";
}
?>
All captured images are displayed in the code running result.
------ Solution --------------------
$ String = 'Your content ';
Preg_match_all ("/] *) \ s * src = ('
------ Solution --------------------
\ ") ([^ '\"] + )('
------ Solution --------------------
\ ")/", $ String, $ matches );
$ New_arr = array_unique ($ matches [2] [0]); // Remove repeated values from the array
Foreach ($ new_arr as $ key => $ val ){
$ Picurl = get_name ($ val); // address of the processed image
Str_replace ($ val, $ picurl, $ string );
}
Function get_name ($ pic_item, $ path = 'upload /')
{
$ Pic_name = paipath.get_unique().'.jpg '; // name the timestamp in microseconds.
$ Write_fd = @ fopen ($ pic_name, "wb ");
@ Fwrite ($ write_fd, CurlGet ($ pic_item ));
@ Fclose ($ write_fd );
Return $ pic_name;
}