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);"> Link to comment https://forums.phpfreaks.com/topic/232771-add-style-color-to-links/ 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. Link to comment https://forums.phpfreaks.com/topic/232771-add-style-color-to-links/#findComment-1197326 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. Link to comment https://forums.phpfreaks.com/topic/232771-add-style-color-to-links/#findComment-1197336 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. Link to comment https://forums.phpfreaks.com/topic/232771-add-style-color-to-links/#findComment-1199916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.