当前位置:网站首页>PHP如何提取字符串中的图片地址
PHP如何提取字符串中的图片地址
2022-06-25 11:00:00 【刘杨造梦程序开发建站】
有时候我们会有一种需求就是提取商品详情中的图片地址给弄成一个数组,从而实现商城用户一键下载图片,PHP提取字符串中的图片地址,实际就是利用正则表达式匹配图片地址,我们直接看代码
<?php
$str='<p><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';//商品详情页代码
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
print_r($match);//$match[0]为提取后的图片,可直接使用,$match[1]为提取后的图片地址,需要写入img标签的src中
?>
边栏推荐
- At 16:00 today, Mr. sunxiaoming, a researcher of the Institute of computing, Chinese Academy of Sciences, took you into the quantum world
- 金仓数据库 KingbaseES 插件force_view
- 手机办理长投学堂证券开户靠谱安全吗?
- 金仓数据库 KingbaseES 插件DBMS_RANDOM
- Introduction to socket UDP and TCP
- Apache ShenYu 入門
- Task03 probability theory
- CSRF attack
- Garbage collection mechanism
- SystemVerilog (XIII) - enumerate data types
猜你喜欢

Netease's open source distributed storage system curve officially became the CNCF sandbox project

Es learning

查询法,中断法实现USART通信

中國信通院沈瀅:字體開源協議——OFL V1.1介紹及合規要點分析

仿真与烧录程序有哪几种方式?(包含常用工具与使用方式)

Double tampon transparent cryptage et décryptage basé sur le cadre minifilter

基于C语言的图书信息管理系统 课程论文+代码及可执行exe文件

After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-7

A five-year technical Er, based on the real experience of these years, gives some suggestions to the fresh students

Android之Kotlin语法详解与使用
随机推荐
Course paper + code and executable EXE file of library information management system based on C language
基于C语言的图书信息管理系统 课程论文+代码及可执行exe文件
What are the ways to simulate and burn programs? (including common tools and usage)
[the path of system analyst] Chapter 6: Double inventory demand engineering (comprehensive knowledge concept)
Query method and interrupt method to realize USART communication
Nuxtjs actual combat case
金仓数据库 KingbaseES 插件force_view
中國信通院沈瀅:字體開源協議——OFL V1.1介紹及合規要點分析
Is it safe for Guosen Securities to open a securities account
Free access to the global human settlements layer (ghsl) dataset from Gee
Démarrer avec Apache shenyu
Kingbasees plug-in DBMS of Jincang database_ session
Gaussdb cluster maintenance case set - slow SQL execution
Checking whether the double value is an integer - Swift - checking if a double value is an integer - swift
Causes and solutions of over fitting
Chinese translation of IMA Lazarus' the new giant, the goddess of Liberty
Big Endian 和 Little Endian
金仓数据库 KingbaseES 插件DBMS_RANDOM
Daily 3 questions (3) - check whether integers and their multiples exist
【上云精品】节能提效!加速纺织业“智造”转型