9.4.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="display: flex;">
<?php
echo deleteImg("Deze <p style='margin: 0px 2px 0px 2px; font-weight: bold;'>tekst </p>bevat geen <img src='plaatje.png'> image");
function deleteImg($html){
$foundstart = false;
$startpos = 0;
$length = 0;
$partOfStr = "";
for($i = 0; $i < strlen($html); $i++){
if(substr($html, $i, 4) == "<img"){
$foundstart = true;
$startpos = $i;
}
if(substr($html, $i, 1) == ">" && $foundstart){
$length = ++$i - $startpos;
$partOfStr .= str_replace(substr($html, $startpos, $length), "(image)", $html);
}
}
return $partOfStr;
}
?>
</body>
</html>
Resultaat
Made by Thijs Aarnoudse