str replace for replacing forward slash

Discussion in 'PHP' started by bugcoder, Sep 4, 2009.

  1. #1
    hi everyone,

    i want to remove </li> inside following html code using str_replace function but cant remove it, and only forward slash is causing this problem. how can i overcome this forward slash issue?

    $my_pages='<li>test text</li>';
    
    echo str_replace('</li>', '', $my_pages);
    PHP:

    quick help please..........
     
    bugcoder, Sep 4, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Works just fine for me, output is:

    <li>test text

    Are you sure you're not doing anything else (have you posted all the code)?
     
    premiumscripts, Sep 4, 2009 IP
  3. bugcoder

    bugcoder Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for reply and also tried with above variable of test text but when i tested separately with original code it didnt replace last closing li
    so actual variable will contain following code

    <li class="page_item page-item-5"><a title="News" href="http://localhost/matinimages/?page_id=5">News</a></li>

    and i dont need the last </li>, which str_replace is not replacing.
     
    Last edited: Sep 4, 2009
    bugcoder, Sep 4, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Still works just the same mate, no </li>. Can you show the actual code you're using? Is the variable coming from $_POST or $_GET? Perhaps you need to remove the slashes if you have magic_quotes enabled?

    You should echo out the before and after string.
     
    premiumscripts, Sep 4, 2009 IP
  5. bugcoder

    bugcoder Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    in actual code im setting variable from wordpress code that automatically generates the above variable for me.

    $my_pages = wp_list_pages('meta_key=News&meta_value=true&echo=0&title_li=');

    :confused:


    i have following code in php.ini file

    magic_quotes_gpc = On

    should other magic quotes also be on?

    Thanks for your time dear.
     
    Last edited: Sep 4, 2009
    bugcoder, Sep 4, 2009 IP
  6. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try
    echo str_replace('</li>', '', stripslashes($my_pages));
    PHP:
     
    premiumscripts, Sep 4, 2009 IP
  7. bugcoder

    bugcoder Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    still now working:(
     
    bugcoder, Sep 4, 2009 IP
  8. bugcoder

    bugcoder Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks a lot for your time dear.............

    the problem was at my end......actually i was checking output using firebug rather than from view source.
    firebug automatically adds closing tag each time it was removed. so i by chance saw view source and it was replacing it with empty string......:mad:


    sorry for this disturbance..
    but thanks again for your help.
     
    bugcoder, Sep 4, 2009 IP
  9. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Haha that's a funny bug :) Anyway glad you got it solved.
     
    premiumscripts, Sep 4, 2009 IP
  10. yuvrajm

    yuvrajm Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    though your problem is solved, still, I shall advise using preg_replace
     
    yuvrajm, Sep 4, 2009 IP