PHP 8.3.22 Released!

Voting

: max(two, zero)?
(Example: nine)

The Note You're Voting On

rajudec at gmail dot com
3 years ago
<?php
//Allow limited span formatting in html text

$str='<span style="text-decoration-line: underline; font-weight: bold; font-style: italic;">White</span>
<span style="text-decoration-line: underline;">RED</span><span style="color:blue">blue</span>'
;

function
next_format($str)
{
$array=array("text-decoration-line"=>"underline","font-weight"=>"bold","font-style"=>"italic");
foreach (
$array as $key=>$val)
{
if(
$str[1]==$key && $str[2]==$val)
{
return
$str[1].': '.$str[2].";";
}
}
return
'';

}
function
next_span($matches)
{
$needFormat=preg_replace_callback('/([a-z\-]+):\s*([^;]+)(;|)/ism',"next_format",$matches[2]);
return
$matches[1].$needFormat.$matches[3];

}
echo
preg_replace_callback(
"/(\<span\s+style\=\")([^\"]+)(\">)/ism",
"next_span",
$str);
?>

<< Back to user notes page

To Top