我的问题concers这个字符串:Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(265)
PHP正则表达式查找字符串包含多个值
我试图找到一种方法来找到这个字符串。但是...在字符串中是:$ product,image和265变量。 所以,我需要找到像字符串:
Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(265)
Mage::helper('catalog/image')->init($product, 'thumb', $image->getFile())->resize(75)
Mage::helper('catalog/image')->init($image, 'mini', $image->getFile())->resize(25)
等...
现在我有这个,但它只是搜索通过量文件Mage::helper('catalog
function listFolderFiles($dir){
$ffs = scandir($dir);
foreach($ffs as $ff){
if($ff != '.' && $ff != '..'){
if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
if(strpos($ff, '.phtml')!==false){
$contents = file_get_contents($dir.'/'.$ff);
$pattern = preg_quote("Mage::helper('catalog", "/");
$pattern = "/^.*$pattern.*\$/m";
if(preg_match_all($pattern, $contents, $matches)){
echo "Found matches in: ".$dir.'/'.$ff."\n";
}
else{
echo "No matches found in: ".$dir.'/'.$ff."\n";
}
}
}
}
}
listFolderFiles('../app/design');
你可以使用“$ pattern =”而不是“$ pattern。=”将下一个模式附加到正则表达式中吗? – EGOrecords 2013-03-03 11:30:23
是的,它也正常工作,像这样:-)我只需要扩展它... – 2013-03-03 11:34:41
很高兴帮助。它现在工作吗? (使用正则表达式时只是一个提示:打印出来,把它放到一个真正的正则表达式框中,看看它是什么构建你的!) – EGOrecords 2013-03-03 11:36:06