Forum Moderators: coopster
[edited by: eelixduppy at 3:37 pm (utc) on Feb 7, 2010]
[edit reason] disabled smileys [/edit]
... if in the content there are images (<img />)
But my goal is to do something only of those images ARE NOT linked (<a><img /></a>)
if (preg_match('/<img[^>]+\s*\/*>/i',$content)) {
if (! preg_match('/<a[^>]+>\s*<img[^>]+\s*\/*>\s*<\/a>/i',$content)) {
return 0;
}
}
// or use $line parsing it line by line
list($err,$newtext)=check_content($orig_content);
//
if ($err) { return_to_form($err,$newtext); }
//
function check_content($content) {
$error=NULL;
// This should actually be a setting.
$span = '<span style="color:red;font-weight:bold">';
$span_close = '</span>';
if (preg_match('/<img[^>]+\s*\/*>/i',$content)) {
if (! preg_match('/<a[^>]+>\s*<img[^>]+\s*\/*>\s*<\/a>/i',$content)) {
$content = htmlentities(preg_replace('/(<img[^>]+\s*\/*>)/i',"$span$1$close_span",$content));
}
}
$ret = Array($error,$content);
return $ret;
}
[edited by: eelixduppy at 2:27 am (utc) on Feb 9, 2010]
[edit reason] disabled smileys [/edit]