Page 1 of 1

preg_match and ||

Posted: Sat Sep 23, 2006 8:32 am
by mlecho
i'm so imbarassed, but if i don't ask, i may go nuts....a while back you all helped introduce me to preg_match so i could pass over all those files that started with "." or "._"....i actually need to evolve that script to avoid the same files, and also other files (those with ".php", and ".txt)....i am trying to incorporate the || operator, but i am not having luck...am i going about this all wrong?

Code: Select all

<?php

$menuType=$_POST['menuType'];
$path=$_SERVER['SCRIPT_NAME'];
$directory="../project";
$tour=$_POST['tour'];
$openDir=opendir($directory);
$subpatterns=array("getDirs.php");
while(false!=($file=readdir($openDir))){
	if(!preg_match('/^\./',$file))|| (!preg_match('/.php/',$file)){
		$files.= "<pict>$file</pict>";
		}
		
}
closedir($openDir);

echo ("&xml=<images>");
echo $files; 
echo ("</images>&");
?>

Posted: Sat Sep 23, 2006 9:15 am
by feyd
Remove the closing and opening parentheses before and after the logical or operator, respectively. I believe your logical-or should be a logical-and. However your check could be performed in a single regex.

Code: Select all

/(?:^\.|\.(?:php|txt)$)/i
may work, however I haven't tested it.

Posted: Sat Sep 23, 2006 9:37 am
by mlecho
ohoh can of worms....where should i start to learn about the meanings of the "?" and "$" and "i"- IE- What terminology should i use in the PHP manual to find out more about how those work in your code?

but many thanks...i will give this a try...it looks promiising

Posted: Sat Sep 23, 2006 10:04 am
by feyd
Read the stickies in this board. If you need further examples, read the threads relating to regex linked from Useful Posts (sticky in PHP - Code), if after reading all those you're still confused, I'll try to explain any remaining questions you may have.