Hide personal files within other files
  • Login
  • Become a blogger
  • Remove invalid characters from a filename

    Posted by thinkdj on December 27th, 2007
    4 Comments | 5,825 pageviews

    <?php
    function filename_safe($filename) {
    $temp $filename;

    // Lower case
    $temp strtolower($temp);

    // Replace spaces with a '_'
    $temp str_replace(" ""_"$temp);

    // Loop through string
    $result '';
    for (
    $i=0$i<strlen($temp); $i++) {
    if (
    preg_match('([0-9]|[a-z]|_)'$temp[$i])) {
    $result $result $temp[$i];
    }
    }

    // Return filename
    return $result;
    }
    ?>

    4 Responses »

    1. Jawsper says:

      uhm… try this:

    2. parveen sharma says:

      How do you remove characters such as “�” from this string, as well as the html code?

    3. Richard says:

      Just what I needed, cheers!

    4. aaaaa says:

      thanks

    Trackbacks/Pingbacks

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    More from "PHP"

    Find what you are looking for

    Recently added

    Categories

    Blogulate

    Keeping you updated of the latest fads and developments of the industry via amalgamated web content.

    Join us

    Post articles on blogulate and monetize them. Learn more »

    Stay updated

    Subscribe now and stay aware of the latest trends and happenings on the www. Get notified via email when we update.

    Enter your email address:

    Blogulate is based on Magnus premium theme by WizeDesigns
    © 2009 Blogulate. Some rights reserved.