Use the preg_replace function to match images and add links
- $ Con = file_get_contents ("http://bbs.it-home.org/wzjs ");
- $ Pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Gif | \. jpg | \. png]) [\ '| \ "]. *? [\/]?> /";
- $ New_con = preg_replace ($ pattern, "$0", $ con );
- Echo $ new_con;
- ?>
-
Note: $0 indicates the matching content. $1 indicates the content of the first () match. $2 indicates the content of the second () match, and so on! In this way, you can add a link to the image. if you are interested, try it yourself. Articles you may be interested in: php code for matching image addresses: a PHP regular expression matching date and time (timestamp conversion) example php matches the regular expression of any Web site php regular expression rewrite html image img path code example PHP regular expression match get URL domain name code php match preg_match_all match picture php regular expression match domain name in URL |