how to remove spaces in query and convert to underscore

Discussion in 'PHP' started by edual200, Mar 15, 2008.

  1. #1
    example i display the query in a echo something like

    mydomain.com/$title1.html but when they contain spaces the url ends up with %20 and i would rather them be underscores, ive searched everywhere and see its not that hard but i cant seem to implement it correctly on the script

    $query = "select * from mytable WHERE address LIKE '%$trimmed%' ";


    // now you can display the results returned
    while ($row= mysql_fetch_array($result)) {
    $title1 = $row["name"];


    echo "<a href=http://www.mydomain.com/$title1.html
    ";
     
    edual200, Mar 15, 2008 IP
  2. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you're looking for str_replace?
    <?php
    // replace $title1 = $row["name"]; with:
    $title1 = str_replace(" ", "_", $row["name"]);
    ?>
    PHP:
     
    Gordaen, Mar 15, 2008 IP