title: How to use the substr() function inside preg_replace() function?
body: <p>This is what I have so far, but whatever I try, my <code>album-content</code> won't get truncated with <code>substr()</code>.</p>
  
  <pre><code>$gallery = preg_replace('/(&lt;div class="album-content"&gt;)(.*?)(&lt;\/div&gt;)/e', "'$1' . substr(\"$2\", 0, 50) . '$3'", $gallery);
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>Turns out my class name was incorrect, and my regex does seem to work.
  I only had to do another str_replace() to un-escape the output.</p>
  
  <pre><code>$gallery = preg_replace('/(&lt;div class="album-desc"&gt;)(.*?)(&lt;\/div&gt;)/e', "'$1' . substr(\"$2\", 0, 50) . '$3'", $gallery);
  $gallery = str_replace('\"album-desc\"', '"album-desc"', $gallery);
  </code></pre>
  
  <p>Output before modifying:</p>
  
  <pre><code>&lt;a href="..." class="album"&gt;
      &lt;div class="album-content"&gt;&lt;p class="album-title"&gt;Album 1&lt;/p&gt;
          &lt;div class="album-desc"&gt;&lt;p&gt;This will be truncated by substr().&lt;/p&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;img src="..." /&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>Thanks all, anyways!</p>