In recent work, the src attribute value (image address) of the img label in the content is often used for reading. Because the attribute value has no regularity, it is a good way to use regular expressions, next we will use php and js for instance
This article mainly introduces PHP based on the regular batch replacement img In the SRC content to achieve the function of thumbnail, involving PHP for the page IMG elements of the regular matching and replacement operations related implementation
PHP uses regular expressions to replace the src content in Img in batches to obtain thumbnails.
This example describes how PHP can obtain thumbnails by replacing the src content in Img in batches based on regular expressions. We will share this with
String to be matched: Regular expression: [^ '"] *) ['"]) | (? [^ s] *)Output result of regular expression matching:XImage/ad1.gifImage/ad2.gifPHP regular expression extraction or the src attribute value of the img element: The code is as
This article describes how to obtain the src attribute value of the link address of an image from img. This article describes how to obtain the src attribute value of the link address of an image from img.
String to be matched:
Regular expression:
/* Regular take picture of any attribute in the IMG tag * *
$word = "111 22 Chinese ';Take the whole picture codePreg_match ('//is ', $word, $matches);echo $matches [0];//results: "
$word = ' 111 22 Chinese ';Take widthPreg_match ('//i ',
/* Regular take picture of any attribute in the IMG tag * *
$word = "111 22 Chinese ';Take the whole picture codePreg_match ('//is ', $word, $matches);echo $matches [0];//results: "
$word = ' 111 22 Chinese ';Take widthPreg_match ('//i ', $word,
PHP is extracting or replacing the IMG Tag property PHP regular Expression matching img, PHP is extracting or replacing any attribute in the image img tag.
123456789101112131415161718192021222324252627282930
/*PHP正则提取图片img标记中的任意属性*/$
This article introduces you to the link address of the SRC attribute value if you get the picture from IMG.
The string to match:
"
Regular Expressions:
[^ '" "]*) [\ '"]) | (? [^\s]*))
Regular match output results:
Ximage/ad1.gifimage/ad2.gif
PHP
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.