zoukankan      html  css  js  c++  java
  • php 正则获取html属性值

    个人不会写正则,但是工作中遇到了又没办法,所以记录下以后再遇到就好找了,呵呵

    言归正传,下面是用正则匹配img的属性的方法:

    1.匹配 “img” 中的 “src” 属性

    $str='<img src="http://aaa.com/images/a.jpg" aid="123456">';

    preg_match_all("/<img.*?src="(.*?)"[^>]*>/i", $str, $match);

    print_r($match);

    2.匹配 “img”中的 “aid” 属性

    $str = '<img src="http://aaa.com/images/a.jpg" aid="123456">';

    preg_match('/aid="(.*)"/isU', $str, $match1);

    echo $match1[1];

    3.匹配字符串中 [[ ]] 括号内的内容

    $str = '你是我的小丫小苹果,怎么爱你都不嫌多[[adfdffdfdfgfgfglkd]]';

    preg_match_all("/[[(.*?)]]/",$content, $result);//正则匹配中括号内的内容

    print_r($result);

     

     
  • 相关阅读:
    SKPhysicsJointPin类
    SKPhysicsJointLimit类
    SKPhysicsJointFixed类
    SKPhysicsJoint类
    SKPhysicsContact类
    SKPhysicsBody类
    SKLabelNode类
    SKNode类
    SKKeyframeSequence类
    Unique Paths II
  • 原文地址:https://www.cnblogs.com/myphper/p/5238897.html
Copyright © 2011-2022 走看看