HTTP/1.1 200 OKServer: nginx/0.7.68Date: Sat, 02 Mar 2013 07:44:57 GMTContent-Type: application/rss+xml; charset=utf-8Transfer-Encoding: chunkedConnection: keep-alive3ab4<?xml version="1.0" encoding="utf-8"?><rss version="2.0"> <channel> <title>CSDN 移动频道(资讯)</title> <link>http://mobile.csdn.net</link> <description>开放平台</description> <lastBuildDate>Sat, 02 Mar 2013 15:44:50</lastBuildDate> <item> <title>移动周报:我为什么弃用Objective-C而选择RubyMotion?</title> <link>http://www.csdn.net/article/2013-03-01/2814309-mobile-weekly-choose-rubymotion-for-ios-dev</link> <description><![CDATA[我们为您精心准备了CSDN移动频道本周最精彩的热点新闻,开发者直言RubyMotion优与劣,讲述为何弃用Objective-C而选择RubyMotion;出生贫苦的Minecraft开发者Notch大神特立独行,始终秉承开放的游戏开发理念;移动互联网大潮来袭,国家级老牌媒体China Daily将怎样拥抱新媒体时代?]]></description> <author>唐小引</author> <pubDate>Fri, 01 Mar 2013 23:41:01</pubDate> <guid>http://www.csdn.net/article/2013-03-01/2814309-mobile-weekly-choose-rubymotion-for-ios-dev</guid> </item> <item> <title>遍地撒网,重点培养,King.com颠覆性游戏商业模式</title> <link>http://www.csdn.net/article/2013-02-27/2814282-king.com-game-launch</link> <description><![CDATA[在App Store的Top Grossing排行榜中,Candy Crush Saga已经排到第二位,仅次于Supercell的Clash of Clans,其开发公司king.com也因此名声大噪,并在移动端打败Zynga,它的成功离不开公司商业模式的创新:发布三部曲+高质游戏+顺势而行。]]></description> <author>陈徐天九</author> <pubDate>Fri, 01 Mar 2013 10:49:52</pubDate> <guid>http://www.csdn.net/article/2013-02-27/2814282-king.com-game-launch</guid> </item> ...
我想用一个正则把上面的内容分成两部分
从空白行分开的两部分为:
1.响应基本信息
HTTP/1.1 200 OKServer: nginx/0.7.68Date: Sat, 02 Mar 2013 07:44:57 GMTContent-Type: application/rss+xml; charset=utf-8Transfer-Encoding: chunkedConnection: keep-alive
2.响应内容
3ab4<?xml version="1.0" encoding="utf-8"?><rss version="2.0"> <channel> <title>CSDN 移动频道(资讯)</title> <link>http://mobile.csdn.net</link> <description>开放平台</description> <lastBuildDate>Sat, 02 Mar 2013 15:44:50</lastBuildDate> <item> <title>移动周报:我为什么弃用Objective-C而选择RubyMotion?</title> <link>http://www.csdn.net/article/2013-03-01/2814309-mobile-weekly-choose-rubymotion-for-ios-dev</link> <description><![CDATA[我们为您精心准备了CSDN移动频道本周最精彩的热点新闻,开发者直言RubyMotion优与劣,讲述为何弃用Objective-C而选择RubyMotion;出生贫苦的Minecraft开发者Notch大神特立独行,始终秉承开放的游戏开发理念;移动互联网大潮来袭,国家级老牌媒体China Daily将怎样拥抱新媒体时代?]]></description> <author>唐小引</author> <pubDate>Fri, 01 Mar 2013 23:41:01</pubDate> <guid>http://www.csdn.net/article/2013-03-01/2814309-mobile-weekly-choose-rubymotion-for-ios-dev</guid> </item> <item> <title>遍地撒网,重点培养,King.com颠覆性游戏商业模式</title> <link>http://www.csdn.net/article/2013-02-27/2814282-king.com-game-launch</link> <description><![CDATA[在App Store的Top Grossing排行榜中,Candy Crush Saga已经排到第二位,仅次于Supercell的Clash of Clans,其开发公司king.com也因此名声大噪,并在移动端打败Zynga,它的成功离不开公司商业模式的创新:发布三部曲+高质游戏+顺势而行。]]></description> <author>陈徐天九</author> <pubDate>Fri, 01 Mar 2013 10:49:52</pubDate> <guid>http://www.csdn.net/article/2013-02-27/2814282-king.com-game-launch</guid> </item> ...
回复讨论(解决方案)
你不读取http头不就行了?
你不读取http头不就行了?
我需要头信息呀。因为Transfer-Encoding: chunked
$arr=preg_split('/(?<=Connection: keep-alive)\s+/s',$s);print_r($arr);
我需要头信息呀。因为Transfer-Encoding: chunked 这个 Transfer-Encoding: chunked 对你而言,毫无意义
PHP code?12$arr=preg_split('/(? 并不是所有的响应头信息都是Connection结束.
引用 2 楼 pktmalaha 的回复:我需要头信息呀。因为Transfer-Encoding: chunked这个 Transfer-Encoding: chunked 对你而言,毫无意义
我当然需要了.因为如果是chunked需要unchunk
引用 2 楼 pktmalaha 的回复:我需要头信息呀。因为Transfer-Encoding: chunked这个 Transfer-Encoding: chunked 对你而言,毫无意义
头信息我是一定需要的.因为我的代码需要它作很多事情.
引用 4 楼 xuzuning 的回复:引用 2 楼 pktmalaha 的回复:我需要头信息呀。因为Transfer-Encoding: chunked这个 Transfer-Encoding: chunked 对你而言,毫无意义
我当然需要了.因为如果是chunked需要unchunk 那就是说你得自己分析返回的头了
如果这样,就不应该是正则的事情了!
你需要逐行读取头信息,直到读到空行(头结束)
这不是一件正则可以胜任的工作
从第一个空行截取两部分不就行了?
然后头部自己再分析
从第一个空行截取两部分不就行了?
然后头部自己再分析
我对正则不怎么会.就是要从空行截取.你能提供一下正则吗
本帖最后由 xuzuning 于 2013-03-04 08:29:12 编辑
引用 6 楼 pktmalaha 的回复:引用 4 楼 xuzuning 的回复:引用 2 楼 pktmalaha 的回复:我需要头信息呀。因为Transfer-Encoding: chunked这个 Transfer-Encoding: chunked 对你而……
我需要头信息来作头信息的工作,需要正文来作正文的工作.而我用socket得来的内容两者混在一起。现在是否可用正则把两者分开呢?我需要你们提供一个正则表达式.而不是告诉我我需要什么
explode("\r\n\r\n", $str, 1);
explode("\r\n\r\n", $str, 1); 看清了我需要的是正则,explode的第一参数是正则吗
如果你得到的响应数据是响应头+响应主题,http响应头以两个空行结尾。可以作为分隔的依据。
另外一种方式,有很多类库可以单独获取响应头和响应主题。如httplib
引用 12 楼 helloyou0 的回复:explode("\r\n\r\n", $str, 1);看清了我需要的是正则,explode的第一参数是正则吗
能不用正则建议不要用,正则并不高效。
用换行截取成两个部份不就可以了吗
如果非要用正则,试试下面的写法
$arr = preg_split('#^[\r\n]#m', $text);print_r($arr);
非要用正则这个...是什么原因?

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

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