I have a text file that contains multiple occurrences of a substring - pin="*****
" where * equals a number.
我有一个文本文件,其中包含多个子字符串 - pin =“*****”,其中*等于一个数字。
The pin number inside the enclose quotes can be N length.
封闭引号内的引脚编号可以是N长度。
What I would like to do is extract the line pin="*****"
or even better just the number inside it and add it to an array for later processing.
我想要做的是提取行pin =“*****”,或者甚至更好地提取其中的数字并将其添加到数组中以供稍后处理。
An example of what the text file looks like is like so
文本文件的样子就是这样的一个例子
[123456]
mystring="srthjkgnyjh"
pin="9898
anotherstring="jghksdfghjkdfg6788678345hjkfsd"
[654321]
mystring="hksfkhjsjl"
pin="4343434"
anotherstring="kdgig89794578945789jkhflsf7865"
etc..
Ideas are much appreciated
非常感谢您的想法
Thank you
1 个解决方案
#1
1
You can use this:
你可以用这个:
preg_match_all('~(?<=\bpin=")[0-9]+(?=")~', $str, $matches);
$result = $matches[0];
(?<=..)
and (?=..)
are a lookbehind and a lookahead. You can find more informations about it here.
(?<= ..)和(?= ..)是一个外观和前瞻。你可以在这里找到更多关于它的信息。
#1
1
You can use this:
你可以用这个:
preg_match_all('~(?<=\bpin=")[0-9]+(?=")~', $str, $matches);
$result = $matches[0];
(?<=..)
and (?=..)
are a lookbehind and a lookahead. You can find more informations about it here.
(?<= ..)和(?= ..)是一个外观和前瞻。你可以在这里找到更多关于它的信息。