Porl123 Posted November 1, 2010 Share Posted November 1, 2010 I've been trying to create a bb code for my site which would allow the attributes color, size and face, but and can't really think of any way it would work. Most of my regex is guesswork so I'm struggling with this a bit. The tag wouldn't strictly need any attributes and could be in any particular order, so it would be a lot like the html <font> tag. If anyone could point me in the right direction I'd appreciate it. here's what I have so far: $string = preg_replace('/\[font([\sface|\ssize|\scolor\]=](.+?)(\]|\s)+)/i','',$string); The bit where I've stumbled is the second parameter. I'm not really where I'd go from there. Anyway, if you can help me, cheers! Link to comment https://forums.phpfreaks.com/topic/217477-font-bb-code/ Share on other sites More sharing options...
Porl123 Posted November 1, 2010 Author Share Posted November 1, 2010 I have it almost exactly how I want it, but I need to change something. $string = preg_replace('/\[font((\scolor|\ssize|\sface)=\"(.+?)\")\]/i','<font\\1>',$string); In most respects, this works, although font size doesn't work in some browsers so I think I'll have to somehow replace it for its CSS equivalent. Does anyone know I can do this? Cheers Link to comment https://forums.phpfreaks.com/topic/217477-font-bb-code/#findComment-1129110 Share on other sites More sharing options...
merylvingien Posted November 1, 2010 Share Posted November 1, 2010 I have a bb code setup and did it like this: $simple_search = array( '/\[font\=(.*?)\](.*?)\[\/font\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', ); $simple_replace = array( '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', ); $text = preg_replace ($simple_search, $simple_replace, $text); Hope this helps Link to comment https://forums.phpfreaks.com/topic/217477-font-bb-code/#findComment-1129133 Share on other sites More sharing options...
Porl123 Posted November 1, 2010 Author Share Posted November 1, 2010 Yeah, I've got something similar to that. I was hoping I could have it all in the one tag. Link to comment https://forums.phpfreaks.com/topic/217477-font-bb-code/#findComment-1129199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.