首先创建一个带有虚拟文件名称的记事本文件。之后,将所有文本放在该文件中。请使用我的脚本从给定的字符串中查找特定的字符串。
一次性
$lines= file('dummy.txt'); // write file name here
$find_word= '';
if(count($lines)>0){
//$lk=array_search('Text-ID',$line);
foreach ($lines as $lineNumber => $line) {
if (strpos($line, 'Text-ID') !== false) {
$start = '<';
$end = '>';
$r = explode($start, $line);
if (isset($r[1])){
$r = explode($end, $r[1]);
$find_word=$r[0];
}
}
}
}
print_r($find_word); exit;
对于多时间
,如果你想找到阵列字符串多的时间和存储,然后使用这个脚本。
$lines= file('dummy.txt'); // write file name here
$find_words= '';
if(count($lines)>0){
//$lk=array_search('Text-ID',$line);
foreach ($lines as $lineNumber => $line) {
if (strpos($line, 'Text-ID') !== false) {
$start = '<';
$end = '>';
$r = explode($start, $line);
if (isset($r[1])){
$r = explode($end, $r[1]);
$find_words[]=$r[0];
}
}
}
}
print_r($find_words); exit;
尝试使用正则表达式与[preg_match()](http://php.net/manual/en/function.preg-match.php)。学习正则表达式时,https://regex101.com是一个很好的资源。 –
有时文本ID可能有所不同。 – Snappy
它是不同的文本“文本ID”或之后的文本? –