This article introduces how to use PHP regular expressions to extract the image address in the page. Friends in need can refer to it.
In html pages, the html code of the image URL specification is generally: 囧2 and 囧4 are optional, but 囧1, A brief discussion on how to extract image addresses using php regular rules, 囧5, and 囧6 are essential to pass XHTML authentication. If we talk about regularity, the shortest match is: (? However, this will report an error in php: Warning: preg_match_all() [function.preg-match-all]: Compilation failed: lookbehind assertion is not fixed length at offset *** in *** The problem is in the zero-width assertion (? Copy code Code example: (?Simple (? Is it okay to list the suffixes of the pictures? For example: Copy code Code example: (?Have you ever seen a picture without a suffix? jbxue.com has many such examples RAW http://us.jbxue.com/content/media/images/Headers/15559182 SmackDown http://us.jbxue.com/content/media/images/Headers/15854138 NXT http://us.jbxue.com/content/media/images/Headers/15929136 Superstars http://us.jbxue.com/content/media/images/Headers/15815850The URLs above are all pictures, but none of them have traditional suffixes. When encountering such addresses, you will still be at a loss. At this point, you can do this: Suggestions on php regular extraction of image addresses: If the format of the image address is img space src=, please use: (? Let’s just introduce these. The writing is a bit messy, but I really hope it can help everyone understand the usage of PHP regularization. |