Results 1 to 3 of 3

Thread: [RESOLVED] How I remove a href link in between div class?

  1. #1
    Join Date
    Jun 2011

    resolved [RESOLVED] How I remove a href link in between div class?

    I'm trying figure out how remove a href link between div class on php script but tough is:

    normal display:

    <div class="showtimes"> <a href="#">10:00am</a> <span class="ghost">|</span> <a href="#>10:30am</a> <span class="ghost">|</span> <a href="#>11:00am</a> </div>

    I need php script remove a href link change to like:


    $page = preg_replace('/<div class\=[\"]showtimes[\"]\>(.*?)<\/div>/si','\\1',$page);


    <div class="showtimes"> 10:00am <span class="ghost">|</span> 10:30am <span class="ghost">|</span> 11:00am </div>

    How I do remove a href link only in between div class?

  2. #2
    Join Date
    Aug 2004
    PHP Code:
    = <<<EOD
    <div class="showtimes"> <a href="#">10:00am</a> <span class="ghost">|</span>
    <a href="#">10:30am</a> <span class="ghost">|</span> <a href="#">11:00am</a> </div>


    $result  $matches[1];
    $result .= preg_replace('#<a\s[^>]*>(.*?)</a>#is''$1'$matches[2]);
    $result .= $matches[3];
    $regexp '#(<div\s[^>]*class=[\'"]showtimes[\'"][^>]*>)(.*?)(</div>)#is';
    $page preg_replace_callback($regexp'foo'$page);

    However, that solution depends on the HTML being properly formatted, and nasty things can happen if it is not, such as when I copied and pasted your HTML that was missing the closing quotes in a couple of the href attributes.

    A more robust solution would be to use the DOM functions to find each div of class "showtimes" and then within them finding each each <a> element, going through contortions to get the text value of each <a>, removing the <a> element and inserting the text, but I'm way too lazy to do that for you right now.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

  3. #3
    Join Date
    Jun 2011


    It's worked! Perfect. Thank you very much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles