Recently in the development process need to get the image of the extracted content address, here simply share the next method, the need for friends can refer to the next
Fascinated by the regular, constantly experimenting with new tricks, first thanks to TNA's non-full output of RSS, and then again thanks to SH's compulsive learning. No TNA, I will not go to see the regular, more do not know that there is such an expression of cattle in the world, not SH's life and death said he did not know, I will not bite the bullet to ponder, to improve. To achieve the same purpose, the regular expression can be not unique, not to do, only you did not think. It can be said that the regular is playing the rules, I love this kind of thing. Nothing is more exciting and awesome than setting the rules to filter things. Share in the PHP environment to use the regular extraction of the image address of some careful: the HTML code of the image URL specification is the code as follows: Embarrassing 1 and 2 is not required, to pass XHTML certification embarrassing 4, embarrassing 5, embarrassing 6 is essential, 3 is the core content, of course, not less. In the right word, the shortest match I write is the following code: (? <=img.+?src= "). *? (? = ") However, this does not work in PHP, it will appear: Warning:preg_match_all () [Function.preg-match-all]: compilation Failed:lookbehind Assertion Is isn't fixed length at offset * * * * * * * tangled for a long time, can not, why? Tried many times, finally found the problem in ("<=img.+?src=") this 0-wide assertion, in PHP, 0 wide assertion does not support similar "*", "+" These infinite times of things, so error, put ". +?" It would be better to fix the length instead. However, it is basically impossible to fix the length between "img" and "src=". Usually, the image address of the IMG and SRC will only be separated by a very simple space, but do not rule out some cases before SRC, img after the ALT, Titlte and other things. So the code is as follows: (? <=img.src= "). *? (? = ") or code as follows: (? <=img\ssrc="). *? (? = ") may be possible, but there is no guarantee that 100% is not a problem. You may ask, the simple code is as follows: (? <=src= "). *? (? = ") not? Usually, you can, but, search the page of the pot friends should know, in addition to the image address with the beginning of SRC, JavaScript address also with SRC start! Moreover, too many of the unpredictable factors of the well-being implied therein, so this seemingly short perfect writing will not work. You may also ask, smart short not, I put the suffix of the picture, it is always OK, such as the code is as follows: (? <=src= "). *?\. (Jpg|jpeg|gif|png|bmp| Jpg| Jpeg| Gif| Png| BMP) Indeed, the wording is quite honest, but have you ever seen a picture without a suffix? WWE.com has many examples of this, RAW http://us.wwe.com/content/media/images/Headers/15559182 smackdown http://us.wwe.com/content/ media/images/headers/15854138 NXT http://us.wwe.com/content/media/images/Headers/15929136 Superstars/http us.wwe.com/content/media/images/headers/15815850 The above URLs are all pictures, but there is no traditional suffix, you are not honest and useless, or can not get them. What do we do? You can also do this with the following code:
http://www.bkjia.com/PHPjc/747076.html www.bkjia.com true http://www.bkjia.com/PHPjc/747076.html techarticle recently in the development process need to retrieve the image of the content of the address, here simply share the next method, the need for friends can refer to the fan on the regular, and constantly try new tricks, the first ...