In my /home folder on the server I have a bunch of other folers. I want to populate a select/option menu with the FOLDERS from /home. Not all the folders need to be listed though, only the ones that are in this format text_text.com
What is actually happening is the folders are e-mail address with _ in replace of the '@' sign and i want the user to beable to select the e-mail address from the option/select box. How do I accomplish this? When I use scandir, i get all the folders (including ., ..) Any help please?!
Help using SCANDIR / GLOB
Moderator: General Moderators
Help using SCANDIR / GLOB
Last edited by bla5e on Thu Jun 17, 2010 8:56 am, edited 1 time in total.
Re: Help using SCANDIR
Cliff note: how do i filter the results that are returned with scandir? trying to eliminate ., .., (which i have done) and anything that isnt in this format text_text.com
Last edited by bla5e on Wed Jun 16, 2010 4:48 pm, edited 1 time in total.
Re: Help using SCANDIR
This is my current code, I am using Smarty as a template engine.
Smarty HTML file
Smarty PHP file
I just need to use a regex/string replace _ with @ and remove the preceding /home
Smarty HTML file
Code: Select all
<select name="domains" id="domains" MULTIPLE>
{foreach from=$files item=email}
{if $email != '..' && $email != '.'}
<option value="">{$email}</option>
{/if}
{foreachelse}
<option>THIS IS AN ERROR!</option>
{/foreach}
</select>
Smarty PHP file
Code: Select all
$files = glob("/home/*_*");
Re: Help using SCANDIR / GLOB
Any help using preg replace with glob/scandir??!
Re: Help using SCANDIR / GLOB
Solution:
Code: Select all
$files = glob("/home/*_*");
$replace = array('/\/home\//', '/_/');
$with = array('', '@');
foreach($files as $file) {
$file = preg_replace($replace, $with, $files);
}
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Help using SCANDIR / GLOB
I see you solved it yourself, however here is an alternative without regex:
Or for fun:
Code: Select all
foreach(glob("/home/*_*") as $file) {
$files[] = str_replace('_', '@', basename($file));
}Code: Select all
foreach(array_map('basename', glob("/home/*_*")) as $file) {
$files[] = str_replace('_', '@', $file);
}mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.