Php regular expression to extract the image url program. Use a regular expression to obtain the IMG tag, extract the SRC of each IMG tag, combine them into your own content, and finally replace the image I want to extract from html. for example, the code first uses a regular expression to obtain the IMG tag, then extracts the SRC of each IMG tag, combines it into its own content, and finally replaces it.
I want to extract html images.
The above address. I want to extract all the addresses that contain 'ico 'and ignore them. for correction, some images are extracted. Some images are not extracted.
Example:
]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>
After improvement ..
The correct answer is as follows:
//
Instance
// Content to be replaced $ content ='
'; // Extract the regular expression preg_match_all ("/] +>/isU", $ content, $ matches); $ img = ""; if (! Empty ($ matches) {// note that the above regular expression indicates that the src value is placed in the third of the array $ img = $ matches [2];} else {$ img = "";} if (! Empty ($ img) {$ img_url = "http ://". $ _ SERVER ['server _ name']; $ patterns = array (); $ replacements = array (); foreach ($ img as $ imgItem) {$ final_imgUrl = $ img_url. $ imgItem; $ replacements [] = $ final_imgUrl; $ img_new = "/". preg_replace ("// I", "/", $ imgItem ). "/"; $ patterns [] = $ img_new;} // sort the array by key ($ patterns); ksort ($ replacements ); // replace content $ vote_content = preg_replace ($ patterns, $ replacements, $ content );
Related articles:
How to use php regular expressions to extract html tags
Php code example for extracting html tags
Use php to extract HTML tags