<?php
$html = file_get_contents('https://printerservis.net/Epson_L3210_Reset.php');

function extractTagContent($html, $startTag = '<div class="ps-article">') {
    $startPos = strpos($html, $startTag);
    if ($startPos === false) {
        echo "startTag not found with exact match!\n";
        // Let's do a case-insensitive regex search for the start position
        if (preg_match('/<div[^>]+class="ps-article"[^>]*>/i', $html, $m, PREG_OFFSET_CAPTURE)) {
            $startTag = $m[0][0];
            $startPos = $m[0][1];
            echo "found tag via regex: $startTag at $startPos\n";
        } else {
            return null;
        }
    }
    
    $contentStart = $startPos + strlen($startTag);
    $length = strlen($html);
    $depth = 1;
    $pos = $contentStart;
    
    while ($pos < $length && $depth > 0) {
        $nextOpen = strpos($html, '<div', $pos);
        $nextClose = strpos($html, '</div', $pos);
        
        if ($nextClose === false) {
            break;
        }
        
        if ($nextOpen !== false && $nextOpen < $nextClose) {
            $depth++;
            $pos = $nextOpen + 4;
        } else {
            $depth--;
            $pos = $nextClose + 6;
        }
    }
    
    return substr($html, $contentStart, $pos - $contentStart - 6);
}

$res = extractTagContent($html);
if ($res) {
    echo "SUCCESS! EXTRACTED LENGTH: " . strlen($res) . "\n";
} else {
    echo "FAILED!\n";
}
