title: PHP string search and replace - possible use of DOM Needed
body: <p>I cant seem to figure out how to achieve my goal.</p>
  
  <p>I want to find and replace a specific class link based off of a generated RSS feed (need the option to replace later no matter what link is there)</p>
  
  <p>Example HTML:</p>
  
  <pre><code>&lt;a class="epclean1" href="#"&gt;
  </code></pre>
  
  <p>WHAT IT SHOULD LOOK LIKE:</p>
  
  <pre><code>&lt;a class="epclean1" href="google.com"&gt;
  </code></pre>
  
  <p>May need to incorporate get element using DOM as the Full php has a created document. If that is the case I would need to know how to find by class and add the href url that way.</p>
  
  <p>FULL PHP:</p>
  
  <pre><code>&lt;?php 
  $rss = new DOMDocument(); 
  $feed = array();
  $urlArray = array(array('url' =&gt; 'https://feeds.megaphone.fm')
  );
  
  foreach ($urlArray as $url) {
      $rss-&gt;load($url['url']);
  
          foreach ($rss-&gt;getElementsByTagName('item') as $node) {
              $item = array ( 
                  'title' =&gt; $node-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue
                  );
              array_push($feed, $item);
          }
      }
  
      usort( $feed, function ( $a, $b ) {
                  return strcmp($a['title'], $b['title']); 
      });
  
      $limit = sizeof($feed);
      $previous = null;
      $count_firstletters = 0;
      for ($x = 0; $x &lt; $limit; $x++) {
          $firstLetter = substr($feed[$x]['title'], 0, 1); // Getting the first letter from the Title you're going to print
          if($previous !== $firstLetter) { // If the first letter is different from the previous one then output the letter and start the UL
              if($count_firstletters != 0) {
                  echo '&lt;/ul&gt;'; // Closing the previously open UL only if it's not the first time
                  echo '&lt;/div&gt;';
  
              }
              echo '&lt;button class="glanvillecleancollapsible"&gt;'.$firstLetter.'&lt;/button&gt;';
              echo '&lt;div class="glanvillecleancontent"&gt;';
              echo '&lt;ul style="list-style-type: none"&gt;';
              $previous = $firstLetter;
              $count_firstletters ++;
          }   
          $title = str_replace(' &amp; ', ' &amp;amp; ', $feed[$x]['title']); 
          echo '&lt;li&gt;'; 
          echo '&lt;a class="epclean'.$i++.'" href="#" target="_blank"&gt;'.$title.'&lt;/a&gt;';
          echo '&lt;/li&gt;';
      }
      echo '&lt;/ul&gt;';  // Close the last UL
      echo '&lt;/div&gt;';
      ?&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>The above fullphp shows on site like so (this is shortened as there is 200+):</p>
  
  <pre><code>    &lt;div class="modal-glanvillecleancontent"&gt;
          &lt;span class="glanvillecleanclose"&gt;×&lt;/span&gt;
  
      &lt;p id="glanvillecleaninstruct"&gt;Select the first letter of the episode that you wish to get clean version for:&lt;/p&gt;
      &lt;br&gt;
  
  
       &lt;button class="glanvillecleancollapsible"&gt;8&lt;/button&gt;
  &lt;div class="glanvillecleancontent"&gt;
  &lt;ul style="list-style-type: none"&gt;
  &lt;li&gt;&lt;a class="epclean1" href="#" target="_blank"&gt;80's Video Vixen Tawny Kitaen 044&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;button class="glanvillecleancollapsible"&gt;A&lt;/button&gt;
  &lt;div class="glanvillecleancontent"&gt;
  &lt;ul style="list-style-type: none"&gt;
  &lt;li&gt;&lt;a class="epclean2" href="#" target="_blank"&gt;Abby Stern&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a class="epclean3" href="#" target="_blank"&gt;Actor Nick Hounslow 104&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a class="epclean4" href="#" target="_blank"&gt;Adam Carolla&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a class="epclean5" href="#" target="_blank"&gt;Adrienne Janic&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>