help with str_replace()

Discussion in 'Web Design and Development' started by Me1000, May 1, 2009.

  1. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #1
    I'm not really sure what my problem is. the code is similar to as follows

    (please note several lines were removed for this post (hence the "..."s) :)

    Code:
    $item['DESCRIPTION'] = 'More Newandnbsp;Photos fromandnbsp;New';
    function addItemToDB($item){
    ...
    $description = $item['DESCRIPTION']; 
    	
    $description = str_replace('andnbsp;', ' ', $description);
    $description = mysql_escape_string(preg_replace('/<[^>]*>/', '', $description)); //parse out the html tags
    ...
    }
    
    When I call the function though, this is outputted for the $description:
    in other words, It's not working!

    Is there something I'm missing?


    :apple:
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    PHP:
    <?php
    $a 
    "More Newandnbsp;Photos fromandnbsp;New\n";
    echo 
    "<p>$a</p>";
    $a str_replace('andnbsp;'' '$a);
    echo 
    "<p>$a</p>";
    ?>
    Output:
    Code:
    More Newandnbsp;Photos fromandnbsp;New
    
    More New Photos from New
    Works for me. So, nothing is wrong with the code you're showing. Maybe a typo somewhere else. I'd suggest some debugging by echoing some variables in other locations and also checking your PHP error log.
     
  3. Me1000 thread starter macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #3
    Debugging by echoing the vars might be a little difficult given the complexities of the script.

    Before I start commenting out a bunch of stuff to do that...

    The string I'm pulling in is not from my own server, so I have very little control over the format of the string. Could the problem be the type of characters it is? (a la unicode, etc...)?
    :apple:
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    I don't believe that should be a problem.
     
  5. Me1000 thread starter macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #5
    Wow, I'm an idiot.

    The data I'm working with is so clunked up that I was running the replace on the wrong data set. XD
    :rolleyes:


    Thank you for your help!

    :apple:
     

Share This Page