• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

Add !important to all css attributes for a:*{}

Using regex I want to add !important to the end of each attributes for all "a" items.

For example,
   a:link {color: red}
Should become:
   a:link {color: red !important}

and

#divID p, #divID a:link, #divID a:hover {color: red; text-decoration: none; font-weight: bold;}

Should become:

#divID p, #divID a:link, #divID a:hover {color: red !important; text-decoration: none !important; font-weight: bold !important;}

This should only be done if  
       a:
is before { and }


a:link { color: white  font-size: 14px; font-family: Helvetica; text-decoration: none }
A:visited {
	color: white  
	font-size: 14px; 
	font-family: Helvetica; 
	text-decoration: none  }
A:active { color: #f4cd03  font-size: 14px; font-family: Helvetica; text-decoration: none  !important }
A:hover {
color: #f4cd03  font-size: 14px; font-family: Helvetica; 
text-decoration: none  }

Open in new window

0
hankknight
Asked:
hankknight
  • 2
1 Solution
 
ddrudikCommented:

<pre>
<?php
function repfunc($match){
  return $match[1].preg_replace('/ {2,}/',' ',preg_replace('/\s*!important(?=\s*!important)/i','',preg_replace('/(?=;|$)/i',' !important',$match[2]))).$match[3];
}
$content = 'a:link { color: white;  font-size: 14px; font-family: Helvetica; text-decoration: none }
A:visited {
	color: white;
	font-size: 14px; 
	font-family: Helvetica; 
	text-decoration: none  }
A:active { color: #f4cd03;  font-size: 14px; font-family: Helvetica; text-decoration: none  !important }
A:hover {
color: #f4cd03;  font-size: 14px; font-family: Helvetica; 
text-decoration: none  }
';
echo "$content<hr>";
$content=preg_replace_callback('/(a:[^{]*\{)([^}]*)(\})/i','repfunc',$content);
echo $content;
?>

Open in new window

0
 
ddrudikCommented:
Thanks for the question and the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now