Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 采集网站 正则表达式和结果输出 问题

采集网站 正则表达式和结果输出 问题

Jun 23, 2016 pm 01:28 PM

采集到输出错误,看看是正则语句问题吗



 function request_by_curl($remote_server, $post_string){    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $remote_server);    curl_setopt($ch, CURLOPT_POSTFIELDS, 'mypost=' . $post_string);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    curl_setopt($ch, CURLOPT_USERAGENT, "Jimmy's CURL Example beta");    $data = curl_exec($ch);    curl_close($ch);    return $data;}$string = request_by_curl("http://www.bwlc.net/bulletin/keno.html",80);  $pat = '/\<tr class=\".*\">[\s\S]*?\<td\>(.*?)\<\/td\>[\s\S]*?\<td\>(.*?)\<\/td\>[\s\S]*?\<td\>(.*?)\<\/td\>[\s\S]*?\<td\>(.*?)\<\/td\>[\s\S]*?\<\/tr\>/i';preg_match_all($pat,$string,$outstr);foreach($outstr as $key => $value){ 	echo "第".$outstr[$key][1]."期,开奖结果为:".$outstr[$key][2]."飞盘:".$outstr[$key][3]."时间:".$outstr[$key][4]."\n";}
Copy after login


回复讨论(解决方案)

你把匹配结果数组的格式理解错了

foreach($outstr[0] as $key => $value){     echo "第".$outstr[1][$key]."期,开奖结果为:".$outstr[2][$key]."飞盘:".$outstr[3][$key]."时间:".$outstr[4][$key]."\n";}
Copy after login
第712522期,开奖结果为:55,09,59,43,04,28,58,70,13,46,42,73,16,51,30,75,11,41,25,69飞盘:01时间:2015-08-20 23:55第712521期,开奖结果为:39,51,10,48,57,25,35,16,78,33,47,20,71,37,42,17,59,49,28,01飞盘:03时间:2015-08-20 23:50第712520期,开奖结果为:38,48,12,27,23,59,13,30,18,60,08,20,15,45,31,05,41,25,01,17飞盘:02时间:2015-08-20 23:45第712519期,开奖结果为:36,28,69,13,42,21,73,05,26,15,58,44,03,56,35,02,19,47,66,06飞盘:01时间:2015-08-20 23:40第712518期,开奖结果为:28,71,47,57,22,66,62,36,02,53,63,07,60,64,35,46,15,78,39,58飞盘:03时间:2015-08-20 23:35第712517期,开奖结果为:74,05,23,11,50,34,04,49,26,01,13,40,54,08,29,24,73,09,31,15飞盘:02时间:2015-08-20 23:30第712516期,开奖结果为:27,40,13,76,38,52,24,75,44,49,14,72,65,35,04,47,67,07,57,71飞盘:01时间:2015-08-20 23:25第712515期,开奖结果为:06,68,31,03,16,63,75,09,44,30,77,12,46,17,79,07,27,15,71,47飞盘:03时间:2015-08-20 23:20第712514期,开奖结果为:01,32,42,06,39,60,20,25,14,75,24,38,19,71,31,33,17,70,41,23飞盘:01时间:2015-08-20 23:15第712513期,开奖结果为:57,11,36,33,74,15,41,31,75,07,32,18,52,42,06,45,34,03,30,44飞盘:02时间:2015-08-20 23:10第712512期,开奖结果为:47,50,13,64,57,32,03,48,58,07,56,61,29,42,12,75,35,55,25,67飞盘:10时间:2015-08-20 23:05第712511期,开奖结果为:49,21,79,07,29,17,64,53,05,60,47,02,20,59,66,12,48,40,67,15飞盘:01时间:2015-08-20 23:00第712510期,开奖结果为:22,80,37,53,27,79,40,46,26,76,61,33,12,42,69,16,60,74,31,39飞盘:01时间:2015-08-20 22:55第712509期,开奖结果为:64,42,07,57,35,01,25,46,66,17,37,33,67,18,41,26,77,14,32,22飞盘:01时间:2015-08-20 22:50第712508期,开奖结果为:62,02,55,63,16,25,06,73,22,52,08,72,27,42,07,71,61,18,01,32飞盘:01时间:2015-08-20 22:45第712507期,开奖结果为:34,64,74,17,55,47,78,21,59,36,79,16,40,29,72,61,15,68,51,13飞盘:02时间:2015-08-20 22:40第712506期,开奖结果为:23,70,67,37,04,57,68,18,66,69,33,46,19,77,45,64,28,75,48,62飞盘:01时间:2015-08-20 22:35第712505期,开奖结果为:58,20,43,27,59,17,31,21,54,44,15,46,39,11,24,45,57,19,41,35飞盘:03时间:2015-08-20 22:30第712504期,开奖结果为:29,53,14,72,42,50,12,71,61,26,03,45,65,05,59,68,23,32,09,74飞盘:02时间:2015-08-20 22:25第712503期,开奖结果为:29,20,67,45,10,50,34,09,22,46,74,14,35,31,77,15,38,28,79,13飞盘:01时间:2015-08-20 22:20第712502期,开奖结果为:49,60,19,30,07,76,27,45,17,70,37,44,11,61,56,21,05,38,58,06飞盘:03时间:2015-08-20 22:15第712501期,开奖结果为:39,04,26,57,65,17,41,36,68,21,43,32,76,12,34,22,64,54,06,60飞盘:02时间:2015-08-20 23:55第712500期,开奖结果为:56,26,02,41,58,05,50,63,22,31,07,72,27,48,18,68,39,46,10,65飞盘:02时间:2015-08-20 22:05第712499期,开奖结果为:50,15,74,63,28,08,45,67,09,54,72,25,43,14,80,31,53,21,76,44飞盘:02时间:2015-08-20 22:00第712498期,开奖结果为:10,52,29,79,03,37,12,62,55,02,58,45,01,21,57,66,08,47,39,78飞盘:04时间:2015-08-20 21:55第712497期,开奖结果为:77,30,49,13,72,36,46,12,70,56,22,03,43,61,05,55,65,18,35,08飞盘:03时间:2015-08-20 21:50第712496期,开奖结果为:15,48,41,06,46,29,02,16,45,49,10,39,27,56,13,40,22,66,09,24飞盘:01时间:2015-08-20 21:45第712495期,开奖结果为:02,41,71,19,25,07,80,24,38,13,79,26,30,11,77,43,20,01,29,50飞盘:04时间:2015-08-20 21:40第712494期,开奖结果为:06,30,66,72,09,50,41,75,14,52,32,76,08,34,18,71,61,07,68,42飞盘:02时间:2015-08-20 21:35第712493期,开奖结果为:78,72,31,08,61,74,13,69,77,28,52,16,80,46,67,26,79,59,63,23飞盘:04时间:2015-08-20 21:30
Copy after login

Statement of this Website
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

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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

See all articles