正则表达提取标签属性值
如何用正则表达是提title的值“The Amazing Spider-Man (2012)”呢?
我自己是用两次preg_split取的,但感觉很低效,有没有朋友给点思路呢?
- HTML code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <td class="image"> <a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)"><img src="/static/imghwm/default1.png" data-src="http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA@@._V1._SX54_CR0,0,54,74_.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="The Amazing Spider-Man (2012)" title="The Amazing Spider-Man (2012)"></a> </td>
------解决方案--------------------
- PHP code
<?php $str='<td class="image"> <a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)"><img src="/static/imghwm/default1.png" data-src="http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA@@._V1._SX54_CR0,0,54,74_.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="The Amazing Spider-Man (2012)" title="The Amazing Spider-Man (2012)"></a> <a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)"> '; $patten = '/title="(.*)"/Uis'; if (preg_match ( $patten, $str, $array )) { print_r($array); } echo "<br>"; $patten1 = '/</a><a href=".*" title="(.*)">/Uis'; if (preg_match_all ( $patten1, $str, $array1 )) { print_r($array1[1]); } ?> <br><font color="#e78608">------解决方案--------------------</font><br> <dl class="code">PHP code<pre class="brush:php;toolbar:false"> $string='<td class="image"> <a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)1"><img src="/static/imghwm/default1.png" data-src="http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA@@._V1._SX54_CR0,0,54,74_.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="The Amazing Spider-Man (2012)" title="The Amazing Spider-Man (2012)3"></a><a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)2"></a> </td>'; if (preg_match_all ( '/(?array(2) { [0]=> array(3) { [0]=> string(38) "title="The Amazing Spider-Man (2012)1"" [1]=> string(38) "title="The Amazing Spider-Man (2012)3"" [2]=> string(38) "title="The Amazing Spider-Man (2012)2"" } [1]=> array(3) { [0]=> string(30) "The Amazing Spider-Man (2012)1" [1]=> string(30) "The Amazing Spider-Man (2012)3" [2]=> string(30) "The Amazing Spider-Man (2012)2" } } */ <div class="clear"> </div>

title是定义网页标题的意思,位于标签内,并且是在浏览器的标题栏中显示的文本,title对于网页的搜索引擎优化和用户体验都非常重要。在编写HTML网页时,应该注意使用相关的关键词和吸引人的描述来定义title元素,以便吸引更多的用户点击和浏览。

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

HTML中的title显示的是网页标题标签,可以让浏览者知道当前页面的主要是讲什么的,所以每个网页都应该有一个单独的title。

phpSpider实用技巧:如何处理网页内容的动态加载问题?在爬取网页数据时,经常会遇到动态加载的内容无法直接通过爬虫获取的问题。这些动态加载的内容可以是通过AJAX请求获取的数据、通过JavaScript进行渲染的DOM元素等。为了解决这个问题,本文将介绍一些在使用phpSpider时处理网页动态加载问题的实用技巧。一、使用网络调试工具查找动态加载的URL

Scrapy是使用Python编写的强大的网络爬虫框架,它可以帮助我们提取网页信息,自动化地操作网站上的内容和数据,而且可以以非常高效的方式处理大规模数据爬取和处理任务。Scrapy提供了强大的Spider框架,API和插件以便于使用和扩展。在这篇文章中,我们将介绍在ScrapySpider中如何支持多种网页解析方法。在开始之前,我们需要了解一些之前的基础

phpSpider进阶指南:如何实现登录态保持的数据爬取?近年来,随着互联网的快速发展,数据爬取在各种应用场景中扮演着重要的角色。而对于一些需要登录态的网站来说,要实现登录状态下的数据爬取就显得尤为重要。本文将介绍如何使用phpSpider实现登录态保持的数据爬取,并给出相应的代码示例。一、概述phpSpider是一个基于PHP语言开发的高性能、低耦合、支持

phpSpider入门指南:如何轻松爬取网页内容?引言:在如今的互联网时代,大量的信息散落在各个网页之中。如果我们能够自动地从这些网页中提取所需的信息,将会极大地提高我们的工作效率。那么如何实现这一目标呢?答案就是使用爬虫技术。本文将介绍如何使用phpSpider进行简单的网页内容爬取,让我们深入了解一下吧!一、什么是phpSpider?phpSpider是

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。<?phpfunction down_file($file_name,$file_sub_dir){//为防止乱码使用函数iconv$file_name=iconv("utf-8","gb2312",$file_


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
