PHP implements Rich text content that is copied from other websites and captures the images locally

Source: Internet
Author: User

<span style= "White-space:pre" ></span>function Getimgbyreg ($str) {$list = array (); $c 1 = preg_match_all ('/ /', $str, $m 1); for ($i = 0; $i < $c 1; $i + +) {$c 2 = Preg_match_all ('/(\w+) \s*=\s* (?:(?:( ["\']) (.*?) (? =\2)) | ([^\/\s]*)) /', $m 1[0][$i], $m 2); for ($j = 0; $j < $c 2; $j + +) {$list [$i] [$m 2[1][$j]] =!empty ($m 2[4][$j])? $m 2[4][$j]: $m 2[3][$j];}} return $list;}
<span style= "White-space:pre" ></span>function replaceimg ($list, $url) {    $newImgTags = array ();    $newImgUrls = Array ();        foreach ($list as $key = + $val) {    $imgTag = '  ';        $newImgTags [$key] = $imgTag;    }        Return Array (' newimgtags ' = $newImgTags, ' newimgurls ' = ' $newImgUrls);}

Simulated use
The directory where you want to save the picture
$dist = '/user/www/img/'. Date ('/y/m/d ');
!is_dir ($dist) && mkdir ($dist, 0777, true);
define (' < Span style= "font-family:arial, Helvetica, Sans-serif;" >urlholder ', </span><span style= "font-family:arial, Helvetica, Sans-serif;" > ' {{urlholer} '); </span><span style= "font-family:arial, Helvetica, Sans-serif;" ></span>//your picture server or directory address, Urlholder. '/img/'. Date ('/y/m/'); 
<p class= "P1" ><span class= "S1" >//This is the simulation you need to replace the user submitted rich text content inside contains the picture address </span></p><p class= "P1" ><span class= "S1" > $content = </span> ' <p>Push&nbsp; pop&nbsp; Pressè?´å?? ĺ?å?? ɀ一个逼ç?? C?? À?å......满物ç?? Æ?? ź "C?? Ľ "éª?ã€? Popå°±æ?¯å?¨è¿?个ç?? Å¿µä¸?å?¬ç "? Å?ºæ?¥ç?? Æ–°ä¸€ä»£æ?? Æ?? À?</p><p>pop使ç "¨objective-c++ç¼–å?? À? Objective-c++æ?¯å¯¹c++ç?? Ɖ©å±?ï¼?å°±å?? Objective-cæ?¯cç?? Ɖ©å±?一æ ã€?è€?è?³äº?为什ä¹?他们ç "¨objective-c++è€?ä¸?æ?¯çº¯ç²¹ç?? Objective-cï¼?å?? Å? Å?¨äº?他们æ?´å–?欢objective-c++ç?? ȯæ³?特性所æ?? ľ?ç?? ľ¿å?©ã€?</p><p><strong>popç?? Æ?¶æ?? </strong></p><p>popç?®å‰?ç "±å?? ĸªé?¨å?? Ç»?æ?? ϼ?å¦?å?¾1所示)ï¼?å?³animationsã€? Engineã€? Utilityã€? Webcoreã€?</p><p>å?¾1 &nbsp; Popæ?¶æ?? Å?¾</p><p>popå?¨ç "»æ?? ĸºæµ?ç?... ï¼?å...¶ç§?å¯?å°±å?¨äº?è¿?个å¼?æ "? ĸç?? Popanimatorã€? Popé€?è¿? Cadisplaylink让å?¨ç "»å®?ç?°äº?60&nbsp; Fpsç?? Ƶ?ç?... æ?? Æ?? ϼ?æ‰ "É€äº?一个游æ?? Ǻ§ç?? Å?¨ç "»å¼?æ"? À?</p><p>cadisplaylinkæ?¯ç±»ä¼¼nstimerç?? Å®?æ-¶å?¨ï¼?ä¸?å?? Ĺ?å¤?å?¨äº?ï¼? Nstimerç "¨äº?æ?" Ä»¬å®?义任å?¡ç?? Ɖ§</p> ' <span class= "S1" >;</span></p> $res = Saveimgfromlist ($content, $dist, $url);
$param = Array ();
What you want $param[' content ' = $res [' content '];
An array of image URLs within the content
$param [' image_urls '] = $res [' Image_urls '];

Then your content is ready to be put into storage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.