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

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

 

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

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

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

print_r($match);

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

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

preg_match('/a>$match1);

 

echo $match1[1];

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

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

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

print_r($result);

 

 

相关文章:

  • 2022-01-06
  • 2021-12-27
  • 2021-11-20
  • 2021-09-29
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2020-11-17
  • 2022-12-23
  • 2021-10-16
  • 2021-09-27
  • 2021-09-24
  • 2022-12-23
相关资源
相似解决方案