| This article describes how to use regular expressions in php to match the image path. if you have any need, refer to this document.
Php regular expression matching image path: Code example:/\ "\ '\ s] *)/I
When you use kindeditor to save an article, you need to take the address of the nth image as the logo image of the article, and save the article code (html of the content) to a field in the database, then save the image address to another field. The above address is to directly obtain the value of the src attribute in the img label. Access this path on the php page using this regular expression. if you can find an image, you can directly use it. if not, you can use preg_match_all to save all addresses to the array and then process the path, for example, you can obtain the file name (excluding the path), recompose the url, and delete the image.
Example: Code example: preg_match_all ("/\" \ '\ s] *)/I ", str_ireplace (" \ "," ", $ content), $ arr );
The content is added with \ escape by php. remove \ first, str_ireplace ("\", "", $ content ), then save the matched content to the $ arr array (two-dimensional ). $ arr [1] is the array that stores the path.
Php regular expression extraction Image address
Refer to the previous article to discuss the php regular expression method for extracting Image addresses. extracting the image addresses in src = is not enough, because it cannot be guaranteed that the address must be an absolute address, what if that is relative? What should I do if the address is albums/Candids/thumb_P1050338.jpg/content/media/touts/5271608/5271654/15320982?
Sometimes you need to add http://example1.com/in front of these addresses, and some even need to add http://example1.com/example2/.../, this is too impractical.
After thinking, the original: http://example.com/and http://example.com////// is the same! Then, if you want to forcibly add a prefix to the two relative addresses mentioned at the beginning and restore them to an absolute address, you just need to add a "/", regardless of whether there is a "/" in the front, "If there is a kill error, you have not let it go", but one more display will still be normal, but one more "/" will be missing. |