tuuga
-
Posts
2 -
Joined
-
Last visited
Never
Posts posted by tuuga
-
-
or
[CODE]
<?php
function highlight($str, $rep) {
$begin = '<span style="background-color:yellow">';
$end = '</span>';
$color = $begin.$rep.$end;
return eregi_replace($rep, $color, $str);
}
$str = 'some text, some text, some text, some text, some text, some text';
$strRep = 'some';
$str = highlight($str, $strRep);
echo $str;
?>
[/CODE]
Checking for specific files via extensions in a folder
in PHP Coding Help
Posted
[CODE]
//$catName -- string ex: './pictures/'
//$allowTypes (optional) - set file types -- array ex: $allowTypes = array('jpg', 'gif');
function openPics ($catName, $allowTypes=NULL) {
//open catalog
$open = opendir($catName);
//check every file
while (false !== ($file = readdir($open))) {
if ($file != '.' && $file != '..' && !is_dir($file)) {
$ex = explode('.', $file);
//if allowTypes is set
if (isset($allowTypes)) {
//if is right type
$type = $ex[count($ex)-1];
if (in_array($type, $allowTypes)) {
$pictures[] = $file;
}
}
//take all file names in array
else {
$pictures[] = $file;
}
}
}
return $pictures;
closedir($open);
}
[/CODE]