note 126746 added to function.preg-match-all
| From: | rajudec at gmail dot com | Date: | Tue, 04 Jan 2022 08:45:00 +0000 |
| Subject: | note 126746 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217466@lists.php.net to get a copy of this message | ||
<?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);
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 14.140.183.194)
----
Manual Page -- https://php.net/manual/en/function.preg-match-all.php
Edit -- https://main.php.net/note/edit/126746
Del: integrated -- https://main.php.net/note/delete/126746/integrated
Del: useless -- https://main.php.net/note/delete/126746/useless
Del: bad code -- https://main.php.net/note/delete/126746/bad+code
Del: spam -- https://main.php.net/note/delete/126746/spam
Del: non-english -- https://main.php.net/note/delete/126746/non-english
Del: in docs -- https://main.php.net/note/delete/126746/in+docs
Del: other reasons-- https://main.php.net/note/delete/126746
Reject -- https://main.php.net/note/reject/126746
Search -- https://main.php.net/manage/user-notes.php