How PHP Extracts the IMG tag properties

Source: Internet
Author: User

Extract_attrib is a PHP script function that extracts the attributes of an image tag , which is extracted using the regular expression method.

This is useful when you want to extract image data from an IMG tag in HTML.

If you know how to modify a regular expression, then the same functionality is extended and can be used to extract any other HTML tags!

Just a few lines of code and hope it works for everyone.

To Extract the IMG tag properties using PHP, follow these steps

functionExtract_attrib ($tag) {    Preg_match_all('/(ID|ALT|TITLE|SRC) = ("[^"]* ")/I ',$tag,$matches); $ret=Array(); foreach($matches[1] as $i=$v) {        $ret[$v] =$matches[2] [$i]; }     return $ret;} $img _tag= ' ; $atts= Extract_attrib ($img _tag);Print_r($atts);

return results

Array (    = "logo"    = "Http://www.devdo.net/wp-content/uploads/2015/06/2015-06-02.jpg" = "Code Farm soldier"    = "Code Farm Soldier Logo")     

How PHP extracts img Tag Properties

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.