Athens_demon Posted April 5, 2011 Share Posted April 5, 2011 Hi there!, I am trying to figure out how to use preg_replace or preg_match. I want to search a text block and add a color style to all the links. How is this possible? Logical Example: Search - > "<a href="whatever.php?id=123&sid=2312">" and replace with <a href="whatever.php?id=123&sid=2312" style="color: rgb(255, 250, 255);"> Quote Link to comment Share on other sites More sharing options...
SamT_ Posted April 5, 2011 Share Posted April 5, 2011 Not tested, but... $buffer = preg_replace("#\<a href=\"([^\"]*)\"#", '<a href="$1" style="color: rgb(0, 0, 0)"', $buffer); Basically, you're finding the opening a tag then replacing it with a new one with color in it. As long as all your links have the href attribute first, it should work on all if them, even with titles. Quote Link to comment Share on other sites More sharing options...
Athens_demon Posted April 5, 2011 Author Share Posted April 5, 2011 Thank you so much! It is working great . I am just used to put styles after href. But I guess that I am ok with this code. Quote Link to comment Share on other sites More sharing options...
habeeb24 Posted April 11, 2011 Share Posted April 11, 2011 You can even insert an id or class to the anchor tag <a> and write css separately in the css page to add style. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.