Solved

String replacement on folders

Posted on 2014-02-25
1
189 Views
Last Modified: 2014-02-25
Hello, I have this that strips out unwanted characters in files and displays the version without the characters on the screen. I'm needing to do the same thing with the folders that I'm displaying. I need to do this because Joomla does not like spaces in the folder names but because of that when I show the folder its all one word. For example, if the name of the folder is Faux Woods Joomla will not allow the admin to put files in but if i have it as FauxWoods it works fine. What I would like to do is have the folder name be Faux_Woods and then strip out the _ when displaying the folder to the screen. Below is the code that is currently being used to strip out characters from files


foreach($files as $file) {
			chdir ($rootDir);
			if (is_dir("$file")){
				echo '<li class="folder"><div class="heading">'.$file.'</div>';
				getDirectory("$path/$file",($level+1));
				echo '</li>';
			} else {
				$info = pathinfo($file);
				$fileNameOnly = basename($file,'.'.$info['extension']);
				$file = str_replace(array('&',','), array('%26','%2C'), $file);
				$fileNameOnly2 = str_replace(array('_','&'), array(' ','&amp;'), $fileNameOnly);
				if (strpos($path, '/secure/') == FALSE)
					echo '<li class="file"><a href="/images/'.$path.'/'.$file.'" target="_blank">'.$fileNameOnly2.'</a></li>';
				else
					echo '<li class="file"><a href="/index.php?option=com_imagedownload&file=/images/'.$path.'/'.$file.'" target="_blank">'.$fileNameOnly2.'</a></li>';
			}
		}
		echo '</ul>';
	} else {
		echo '<ul><li class="noDownloads">No Downloads Available.</li></ul>';
	}
}

Open in new window

0
Comment
Question by:DancingFighterG
1 Comment
 

Accepted Solution

by:
DancingFighterG earned 0 total points
Comment Utility
Ok, I figured it out. Thanks anyway
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now