1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Quick regexp question i think, remove the last <li>..</li>??

Discussion in 'PHP' started by 123GoToAndPlay, May 19, 2010.

  1. #1
    HI there,

    I am using a trim_text function in combo with some simple str_replace to make sure the code ends with </ul>

    But i like to remove the last
    <li>whatever</li>
    Code (markup):
    
    $res = preg_replace('<li>????</li>','',$content);
    
    Code (markup):
    regards,
    SEMrush
     
    123GoToAndPlay, May 19, 2010 IP
    SEMrush
  2. abstractworld

    abstractworld Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    why don't you use strrpos to get last position of li...using regex it would be difficult to get LAST li
    use this:
    $pos = strrpos($content, "<li>");
    This will give you position of last li
    $res = substr($content, 0 , $pos+1);

    Hope this helps...
     
    abstractworld, May 19, 2010 IP
  3. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi abstractworld,

    You are right i am puzzled but your suggestion seems to work almost as i want it.

    i had to $pos-1 and add </ul>
     
    123GoToAndPlay, May 19, 2010 IP