Files
php_8/regexp/replace_callback.php

10 lines
269 B
PHP

<?php
$str = '<hTmL><bOdY style="background: white;">Hello, world!</bOdY></html>';
$str = preg_replace_callback(
'{(?<btag></?)(?<content>\w+)(?<etag>.*?>)}s',
fn($m) => $m['btag'].strtoupper($m['content']).$m['etag'],
$str);
echo htmlspecialchars($str);