Is it possible to write a regular expression to replace everything between <div id=”somevalue123” class=”text-block”> and </div>? I can do this but the problem I am having is that there are other div nodes within the string.
Here is the current regular expression that I am using:
public static function replaceStringBetween($start, $end, $new, $source, $limit = 1)
{
    // Reinitialize the replacement count
    self::$replacement_count = 0;
    // Try to perform the replacement
    $result = preg_replace('#('.preg_quote($start) . ')(.*)('.preg_quote($end) 
        . ')#is', '$1' . $new . '$3', $source, $limit, $count);
    if ($count > 0)
    {
        self::$replacement_count++;
        return $result;
    }
    // As a fallback, try again with a different method
    $result = preg_replace ("#{$start}(.*){$end}#is", $new, $source, $limit, $count);
    if ($count > 0)
    {
        self::$replacement_count++;
        return $result;
    }
    // Return the original
    return $source;
}
I am passing an HTML file as the source, of course. Thanks
 
     
    