Results 1 to 3 of 3

Thread: str_replace Help!

  1. #1
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Question str_replace Help!

    I can't get the code below to work... I'm new to str_replace - this is my first time using it!

    I'm trying to get it so special characters are removed from the value...It's messing up jQuery...
    Code:
    <ul>
    <?php
    $sql01 = mysql_query("SELECT * FROM pages");
    while($menu = mysql_fetch_array($sql01)){
    	$themenuitem = $menu[3];
    	$replaceit = str_replace($fooarray, "_", $themenuitem);
    	$fooarray = array(":", "!", "?", "<", ">", "(", ")", "%", "$", "#", "@", "*", "&", "^", "{", "}", "[", "]", "/", "\\", "'", "\"", "+");
    ?>
    <li><a href="?page=<?php echo $menu[3]; ?>" id="<?php echo $replaceit; ?>"><?php echo $menu[0]; ?></a></li>
    <?php
    }
    ?>
    </ul>
    Thanks,
    X96
    Last edited by X96 Web Design; 10-01-2009 at 03:41 AM.
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try placing $fooarray before $replaceit.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Thanks! That would do it!

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •