search
HomeBackend DevelopmentPHP Tutorialphp正则提取img全部属性值

php正则提取img所有属性值

<span style="color: #800080;">$ext</span> = 'gif|jpg|jpeg|bmp|png';<span style="color: #008000;">//</span><span style="color: #008000;">罗列图片后缀从而实现多扩展名匹配 by http://www.k686.com 绿色软件  </span><span style="color: #800080;">$str</span> = ''<span style="color: #000000;">;    </span><span style="color: #800080;">$list</span> = <span style="color: #0000ff;">array</span>();    <span style="color: #008000;">//</span><span style="color: #008000;">这里存放结果map  </span><span style="color: #800080;">$c1</span> = <span style="color: #008080;">preg_match_all</span>('/php正则提取img所有属性值/', <span style="color: #800080;">$str</span>, <span style="color: #800080;">$m1</span>);  <span style="color: #008000;">//</span><span style="color: #008000;">先取出所有img标签文本  </span><span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0; <span style="color: #800080;">$i</span>$c1; <span style="color: #800080;">$i</span>++) {    <span style="color: #008000;">//</span><span style="color: #008000;">对所有的img标签进行取属性  </span>    <span style="color: #800080;">$c2</span> = <span style="color: #008080;">preg_match_all</span>('/(\w+)\s*=\s*(?:(?:(["\'])(.*?)(?=\2))|([^\/\s]*))/', <span style="color: #800080;">$m1</span>[0][<span style="color: #800080;">$i</span>], <span style="color: #800080;">$m2</span>);   <span style="color: #008000;">//</span><span style="color: #008000;">匹配出所有的属性  </span>    <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$j</span>=0; <span style="color: #800080;">$j</span>$c2; <span style="color: #800080;">$j</span>++) {    <span style="color: #008000;">//</span><span style="color: #008000;">将匹配完的结果进行结构重组  </span>        <span style="color: #800080;">$list</span>[<span style="color: #800080;">$i</span>][<span style="color: #800080;">$m2</span>[1][<span style="color: #800080;">$j</span>]] = !<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$m2</span>[4][<span style="color: #800080;">$j</span>]) ? <span style="color: #800080;">$m2</span>[4][<span style="color: #800080;">$j</span>] : <span style="color: #800080;">$m2</span>[3][<span style="color: #800080;">$j</span><span style="color: #000000;">];      }  }  </span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$list</span>); <span style="color: #008000;">//</span><span style="color: #008000;">查看结果变量</span>

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
img文件怎么打开img文件怎么打开Sep 18, 2023 am 09:40 AM

打开img文件的方法有使用虚拟光驱软件打开、使用压缩软件打开和使用专用工具打开。详细介绍:1、使用虚拟光驱软件打开,下载并安装一个虚拟光驱软件,右键单击img文件,选择“打开方式”或“关联程序”,在弹出的对话框中选择安装的虚拟光驱软件,虚拟光驱软件会自动加载img文件,并将其作为虚拟光驱中的光盘映像,双击虚拟光驱中的光盘图标,即可打开img文件并访问其中的内容等等。

img文件如何打开img文件如何打开Jul 06, 2023 pm 04:17 PM

img文件打开的方式:1、确认img文件路径;2、使用img文件打开器;3、选择打开方式;4、查看图片;5、保存图片。img文件是一种常用的图像文件格式,通常用于存储图片数据。

img是什么格式img是什么格式Mar 17, 2023 am 10:33 AM

img是一种文件压缩格式,主要是为了创建软盘的镜像文件,它可以用来压缩整个软盘或整片光盘的内容;使用“.IMG”这个扩展名的文件就是利用这种文件格式来创建的;img文件包括3个基本节点,分别是“Ehfa_HeaderTag”、“Ehfa_File”和“Ehfa_Entry”。

php如何实现Redis的List操作php如何实现Redis的List操作May 26, 2023 am 11:51 AM

List操作//从list头部插入一个值。$ret=$redis->lPush(&#39;city&#39;,&#39;guangzhou&#39;);//从list尾部插入一个值。$ret=$redis->rPush(&#39;city&#39;,&#39;guangzhou&#39;);//获取列表指定区间中的元素。0表示列表第一个元素,-1表示最后一个元素,-2表示倒数第二个元素。$ret=$redis->l

java中JSONArray互相转换List怎么实现java中JSONArray互相转换List怎么实现May 04, 2023 pm 05:25 PM

1:JSONArray转ListJSONArray字符串转List//初始化JSONArrayJSONArrayarray=newJSONArray();array.add(0,"a");array.add(1,"b");array.add(2,"c");Listlist=JSONObject.parseArray(array.toJSONString(),String.class);System.out.println(list.to

如何使用C#中的List.Sort函数对列表进行排序如何使用C#中的List.Sort函数对列表进行排序Nov 17, 2023 am 10:58 AM

如何使用C#中的List.Sort函数对列表进行排序在C#编程语言中,我们经常需要对列表进行排序操作。而List类的Sort函数正是为此设计的一个强大工具。本文将介绍如何使用C#中的List.Sort函数对列表进行排序,并提供具体的代码示例,帮助读者更好地理解和应用该函数。List.Sort函数是List类的一个成员函数,用于对列表中的元素进行排序。该函数接

为什么在Python中list.sort()不会返回已排序的列表?为什么在Python中list.sort()不会返回已排序的列表?Sep 18, 2023 am 09:29 AM

示例在这个例子中,我们先看看list.sort()的用法,然后再继续。在这里,我们创建了一个列表并使用sort()方法按升序排序-#CreatingaListmyList=["Jacob","Harry","Mark","Anthony"]#DisplayingtheListprint("List=",myList)#SorttheListsinAscendingOrdermyList.sort(

Java中如何将数组转换为ListJava中如何将数组转换为ListApr 19, 2023 am 09:13 AM

一.最常见方式(未必最佳)通过Arrays.asList(strArray)方式,将数组转换List后,不能对List增删,只能查改,否则抛异常。关键代码:Listlist=Arrays.asList(strArray);privatevoidtestArrayCastToListError(){String[]strArray=newString[2];Listlist=Arrays.asList(strArray);//对转换后的list插入一条数据list.add("1"

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool