I have a text file and I want to search it like There are many lines in the file and I want to search each line, that it should return that line has the keyword "function" and that function should be called from the same line.
means I want to search keyword in same same regex.
for eg. please check following test.txt
if line 2 of txt file has function f3
but in that line there are no any calling function of f3
, so that line should not be count.
but line 3 of text file has function f1
and f1()
also called from same line so it will be count.
the following is the file content from which I want to search lines.
test.txt
$xwbl209= "SN),AK mtyCcMXQHJ.T0-3qjfY5GnRl";
$k =5; function f3($a,$b,$c){ /*...*/ };
function f1(){ /*...*/ }; $a=1; $b=5; f1();
$aayw572 = f3($xwbl209{5},'',$xwbl209{10});
$k=10; function f2(){ /*...*/ }; $j=1; f1();
$bhzs038 = f3($xwbl209{5},$xwbl209{6},$xwbl209{8});
$aa = "aa"; function f4(){ /*...*/ }; $b=1; f4();
$b = "b"; function f5(){ /*...*/ }; $b=1; f4();
$aa = "aa"; function f6(){ /*...*/ }; $b=1; f6();
$bhzs038 = f3($xwbl209{5},$xwbl209{6},$xwbl209{8});
From the code below I was trying.
$lines = explode("
", file_get_contents('test.txt'));
$new_line = array();
foreach($lines as $line){
if(preg_match(/somthing pattern/, $line)){
$new_line[] = $line;
}
}
print_r($new_line);
I also tried the following pattern, but it doesn't work.
/function ([^(])+(.*$1().*/g
The output of $new_line
should be as follow.
function f1(){ /*...*/ }; $a=1; $b=5; f1();
$aa = "aa"; function f4(){ /*...*/ }; $b=1; f4();
$aa = "aa"; function f6(){ /*...*/ }; $b=1; f6();
Can you help me please?
Thank you!!
question from:
https://stackoverflow.com/questions/65917157/how-to-find-any-keyword-in-same-regex-in-preg-match-php 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…