2013-06-23 04:33:51 W3SVC1539885 198.56.185.162 GET /robots.txt - 80 - 66.249.75.65 Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) 404 0 2
我想分别匹配日期2013-06-23/时间04:33:51/服务器ip198.56.185.162/文件地址robots.txt/蜘蛛ip66.249.75.65/蜘蛛信息Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html)/状态码404 0 2/,这个如何精确匹配?
回复讨论(解决方案)
最好举一个特定的例子,然后给出你期望的结果,你的问题表示看不懂
最好举一个特定的例子,然后给出你期望的结果,你的问题表示看不懂
代码就是特定的例子,我想取的值标注在下面,就是想写一句话正则匹配,用pregmatch这种生成一个数组然后我再干点其他的事。
我想这个日期的格式应该是固定的,你可以按空格将它们分割,例如
$log = '2013-06-23 04:33:51 W3SVC1539885 198.56.185.162 GET /robots.txt - 80 - 66.249.75.65 Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) 404 0 2';var_dump( explode(' ', $log) ); /**array(14) { [0]=> string(10) "2013-06-23" [1]=> string(8) "04:33:51" [2]=> string(12) "W3SVC1539885" [3]=> string(14) "198.56.185.162" [4]=> string(3) "GET" [5]=> string(11) "/robots.txt" [6]=> string(1) "-" [7]=> string(2) "80" [8]=> string(1) "-" [9]=> string(12) "66.249.75.65" [10]=> string(72) "Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html)" [11]=> string(3) "404" [12]=> string(1) "0" [13]=> string(1) "2"}*/
我想这个日期的格式应该是固定的,你可以按空格将它们分割,例如
$log = '2013-06-23 04:33:51 W3SVC1539885 198.56.185.162 GET /robots.txt - 80 - 66.249.75.65 Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) 404 0 2';var_dump( explode(' ', $log) ); /**array(14) { [0]=> string(10) "2013-06-23" [1]=> string(8) "04:33:51" [2]=> string(12) "W3SVC1539885" [3]=> string(14) "198.56.185.162" [4]=> string(3) "GET" [5]=> string(11) "/robots.txt" [6]=> string(1) "-" [7]=> string(2) "80" [8]=> string(1) "-" [9]=> string(12) "66.249.75.65" [10]=> string(72) "Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html)" [11]=> string(3) "404" [12]=> string(1) "0" [13]=> string(1) "2"}*/
我想这个日期的格式应该是固定的,你可以按空格将它们分割,例如
$log = '2013-06-23 04:33:51 W3SVC1539885 198.56.185.162 GET /robots.txt - 80 - 66.249.75.65 Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) 404 0 2';var_dump( explode(' ', $log) ); /**array(14) { [0]=> string(10) "2013-06-23" [1]=> string(8) "04:33:51" [2]=> string(12) "W3SVC1539885" [3]=> string(14) "198.56.185.162" [4]=> string(3) "GET" [5]=> string(11) "/robots.txt" [6]=> string(1) "-" [7]=> string(2) "80" [8]=> string(1) "-" [9]=> string(12) "66.249.75.65" [10]=> string(72) "Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html)" [11]=> string(3) "404" [12]=> string(1) "0" [13]=> string(1) "2"}*/
但是服务器日志不是每行都是这样的,有很多#开头的,所以才想做个正则过滤掉其他格式的。
这个分不能浪费了
日志文件一般都很大
你需要在循环中逐行读取,拆分成数组

tomakephpapplicationsfaster,關注台詞:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,關注台詞:1)啟用opcodeCachingwithapCutoredUcescriptexecutiontime.2)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

依赖注入(DI)通过显式传递依赖关系,显著提升了PHP代码的可测试性。1)DI解耦类与具体实现,使测试和维护更灵活。2)三种类型中,构造函数注入明确表达依赖,保持状态一致。3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

phpisusedforsenderemailsduetoitsbuilt-inmail()函數andsupportivelibrariesLikePhpMailerAndSwiftMailer.1)usethemail()functionForbasiceMails,butithasimails.2)butithasimail.2)

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显著提升PHP应用的性能。

依賴性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增強量強制性,可驗證性和MATIALWINABIOS.ItallowSpasspassingDepentenciesLikEdenciesLikedAbaseConnectionStoclasseconnectionStoclasseSasasasasareTers,interitationAseTestingEaseTestingEaseTestingEaseTestingEasingAndScalability。

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能