A little help about str replace

Discussion in 'PHP' started by turifungia, Dec 8, 2007.

  1. #1
    Hi there,
    i need replace this page:
    test one.html
    with
    test_one.html

    I try this code
    $url = str_replace(" ","_",$datas[category]);

    But don't work...

    This is my url string:
    
    <a href='$url/$datas[category].html'>$cats</a>";
    
    PHP:
    Someone can help me please?

    Thanks in advance
     
    turifungia, Dec 8, 2007 IP
  2. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This might not working because you are setting $url as the variable to store the replacement into but you need to save it to the original source in the $datas array

    Try this

    
    $url = 'http://www.yoursite.com';
    $datas['category'] = str_replace(" ","_",$datas['category']);
    
    echo "<a href='".$url."/".$datas['category'].".html'>".$cats."</a>";
    
    PHP:
    Hope this helps
     
    tonybogs, Dec 8, 2007 IP
  3. turifungia

    turifungia Well-Known Member

    Messages:
    465
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Yes it works.. i really appreciate :)

    Many thanks tonybogs
     
    turifungia, Dec 8, 2007 IP