文件中带有值的preg_match_all字符串 [英] preg_match_all string from file with value

查看:98
本文介绍了文件中带有值的preg_match_all字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按值搜索有关选项内容的文件名lll.php

I need to search into file name lll.php about content of option by value

我的文件lll.php

my file lll.php

<option value="n-7069">1</option>
<option value="n-7066">3</option>
<option value="n-7065">2</option>

我尝试使用此代码,但无法与我一起使用

I try this code but not work with me

我的搜索代码,例如n-7065

my search code like n-7065

$ccc2=$rd33fddf33do['contery'] ; 

我的文件内容值

$llll= file_get_contents('lll.php');

但是现在可以和我一起使用

but it now work with me

preg_match_all('|<option *?</option>|ms', $llll, $matches);
foreach ($matches[0] as $select) {
    preg_match_all('|value='.$ccc2.'|', $select, $matches2);
    var_dump($matches2[1]);
}

推荐答案

preg_match('#<option value="'.$ccc2.'"(.*?)>(.*?)</option>#im', $llll, $body); 
print_r($body[2]); 

这篇关于文件中带有值的preg_match_all字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆