Str replace function. How much do you know it?

Discussion in 'PHP' started by becoolufull99, Jun 28, 2010.

  1. #1
    alrht, I have this code

    <?php echo ltrim(str_replace(':','',wp_title(':',false)));?>.html">

    In this I have removed colon ( : ) from wp_title and now I want to replace all the spaces in wp_title with dash too.

    Can you help me?

    If you can't get above words, see this
    Let wp_title is [ Hello: friend]
    current output- Hello friend.html
    I want it to be- Hello-friend.html

    Please help me
     
    becoolufull99, Jun 28, 2010 IP
  2. Kaimi

    Kaimi Peon

    Messages:
    60
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not preg_replace?
     
    Kaimi, Jun 28, 2010 IP
  3. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #3
    use array: str_replace(array(':',' '), array('','-'), $str);
     
    gapz101, Jun 28, 2010 IP
  4. becoolufull99

    becoolufull99 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am not a pro in php. I managed to use ARRAY but its creating extra dash.

    My output is [--Hello-friend.html]

    The two extra dashes before hello.

    How can I remove them?
     
    Last edited: Jun 28, 2010
    becoolufull99, Jun 28, 2010 IP
  5. becoolufull99

    becoolufull99 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I got it working

    Used trim((the above code),'-')

    Working with trim.
     
    becoolufull99, Jun 28, 2010 IP