Re: ereg help!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



steve wrote:
I have a dir of html files that link to websites, i would like to read the dir and print a list of those files as a link. Which the script i have does. I would like to take this one step further and replace the ".html" extension with ".com" so it winds up being:
website.com instead of website.html

I am apparently having problems getting my head around eregi enough to acomplish this.

any help is greatly appreciated.

<?
$source_dir = "./mydir";

$dir=opendir($source_dir);
$files=array();
while (($file=readdir($dir)) !== false)
{


if ($file != "." && $file != ".." && strpos(strtolower($file),".php") === false)
	{
	array_push($files, $file);
	}
}
closedir($dir);
sort($files);
foreach ($files as $file)
{

echo "<A href='$file'>$file<br>";


}
?>


I usually use preg_* functions so here's my go:

echo preg_replace('/\.php$/', '.com', $file);

The '$' at the end makes sure it's a .php file and won't cause problems with files like xyz.php.txt .

(otherwise I'd just use a straight str_replace).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux