[英]PHP: Regex To Search And Store For A Random String Between Fixed String
我正在開發一個PHP應用程序,該程序從隨機生成的遠程服務器中提取數據。 我正在尋找一個正則表達式,它將幫助我從此命令中獲取粗體數據:
$.post('sitelink',{opt:'check_log',args:{aid:**2540**,lid:**7**,oid:**0**,ref: 'https://www.google.com'}},
我想編寫一個正則表達式,將以上所有3個加粗的字符串(或數字)存儲在3個單獨的變量中或作為數組存儲。 這些數字是隨機生成的。
我該如何實現? 目前,我正在通過將整個文檔拆分為數組,然后運行3次循環,然后搜索逗號來打破循環等來提取此文件。 與正則表達式相比,我認為這太慢了。
任何幫助,將不勝感激!
假設您將字符串放在$ data變量中進行測試,則可以使用preg_match函數:
preg_match("/aid:\*\*([0-9]+)\*\*/,lid:\*\*([0-9]+)\*\*,oid:\*\*([0-9]+)\*\*/", $data, $matches);
您的3個變量由()捕獲,然后存儲在$ matches [1],$ matches [2],$ matches [3]中。
注意: $ matches [0]包含原始的$ data字符串。
沒關系的家伙。 我找到了。 它有點hacky,但它適用於我的應用程序。
對於字符串: $.post('sitelink',{opt:'check_log',args:{aid:2540,lid:7,oid:0,ref: 'https://www.google.com'}},
$contents = explode("$.post('http://bc.vc/fly/ajax.fly.php',{opt:'check_log',args:{", $contentget);
$content = explode(',', $contents[1]);
$aid = intval(preg_replace('/[^0-9]+/', '', $content[0]), 10);
$lid = intval(preg_replace('/[^0-9]+/', '', $content[1]), 10);
$oid = intval(preg_replace('/[^0-9]+/', '', $content[2]), 10);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.