Q:

PHP - delete string from start to endpoint

I have a string in PHP like this:
<nav role="navigation" class="main-navigation" id="site-navigation">
  <li class="page_item page-item-2"><a href="/sample-page/">Sample Page</a></li>
  <li class="page_item page-item-69 current_page_item"><a href="/transport-quote-step-2/">Transport Quote Step 2</a></li>
  <li class="page_item page-item-70"><a href="/transport-quote-step-3/">Transport Quote Step 3</a></li>
  <li class="page_item page-item-71"><a href="/transport-quote-step-4/">Transport Quote Step 4</a></li>
</nav>

Now I want to locate LI element that contains class "page-item-69" and I need to delete whole LI element so I can get output like this:
<nav role="navigation" class="main-navigation" id="site-navigation">
  <li class="page_item page-item-2"><a href="/sample-page/">Sample Page</a></li>
  <li class="page_item page-item-70"><a href="/transport-quote-step-3/">Transport Quote Step 3</a></li>
  <li class="page_item page-item-71"><a href="/transport-quote-step-4/">Transport Quote Step 4</a></li>
</nav>

A:

In today's PHP world, the preferred method here would be using PHP's DOM model.  Sadly, I am still learning this myself and do not have a good grasp on this.  For what it's worth, though, here is my stab at it.  (There may be an easier/better way to do this.)
$string = '<nav role="navigation" class="main-navigation" id="site-navigation">
  <li class="page_item page-item-2"><a href="/sample-page/">Sample Page</a></li>
  <li class="page_item page-item-69 current_page_item"><a href="/transport-quote-step-2/">Transport Quote Step 2</a></li>
  <li class="page_item page-item-70"><a href="/transport-quote-step-3/">Transport Quote Step 3</a></li>
  <li class="page_item page-item-71"><a href="/transport-quote-step-4/">Transport Quote Step 4</a></li>
</nav>';

$dom_document = new DOMDocument(); // CREATE A NEW DOCUMENT
$dom_document->loadHTML($string); // LOAD THE STRING INTO THE DOCUMENT
$lis = $dom_document->getElementsByTagName('li'); // PULL OUT THE LIS OUT OF THE DOCUMENT

// LOOP THROUGH EACH LI
foreach ($lis AS $li) {

    // IF WE FIND page-item-69, DELETE THE ITEM
    if (preg_match('/page-item-69/', $li->getAttribute('class'), $m)) {
        $li->parentNode->removeChild($li);
    }

}

$new_string_2 = $dom_document->saveHTML(); // WRITE THE CHANGES TO A STRING

print $new_string_2;

That does seem to work for me, but since I am old school, here is how one would go about it using REGEX:
$string = '<nav role="navigation" class="main-navigation" id="site-navigation">
  <li class="page_item page-item-2"><a href="/sample-page/">Sample Page</a></li>
  <li class="page_item page-item-69 current_page_item"><a href="/transport-quote-step-2/">Transport Quote Step 2</a></li>
  <li class="page_item page-item-70"><a href="/transport-quote-step-3/">Transport Quote Step 3</a></li>
  <li class="page_item page-item-71"><a href="/transport-quote-step-4/">Transport Quote Step 4</a></li>
</nav>';

$string = preg_replace('~(\s*)<li class="page_item page-item-69.*?</li>~i', '', $string);

print $string;

This will output the following:
<nav role="navigation" class="main-navigation" id="site-navigation">
  <li class="page_item page-item-2"><a href="/sample-page/">Sample Page</a></li>
  <li class="page_item page-item-70"><a href="/transport-quote-step-3/">Transport Quote Step 3</a></li>
  <li class="page_item page-item-71"><a href="/transport-quote-step-4/">Transport Quote Step 4</a></li>
</nav>

