techcone Posted December 12, 2008 Share Posted December 12, 2008 I have a text file containing this : <font face="Book Antiqua"><font size="5"><font color="Orange">asdasdasdasd</font></font></font> I want to replace second font tag with this [size=5] so code appears <font face="Book Antiqua">[size=5]<font color="Orange">asdasdasdasd</font>[/size]</font> But I am getting : <font face="Book Antiqua">[size=5]<font color="Orange">asdasdasdasd</font></font>[/size] or this <font face="Book Antiqua">[size=5]<font color="Orange">asdasdasdasd[/size]</font></font> depending on whether i use ? or not. How can i select middle tag ? Regex used : <font size=\"(.*?)\">(.*?)<\/font> Link to comment https://forums.phpfreaks.com/topic/136707-simple-regex-problem/ Share on other sites More sharing options...
jeepin81 Posted December 12, 2008 Share Posted December 12, 2008 what are you trying to do? what is "" That's not HTML, CSS or anything i've seen, so maybe that is why I'm confused? Are you trying to make the font size dynamic, so it can be adjusted by the user? If so, just use a variable. <?PHP $fontSIZE = $_GET['size']; ?> <font face="Book Antiqua" size="<?PHP echo $fontSIZE; ?>" color="Orange">asdasdasdasd</font> Again - if you could explain a little more, maybe there is a better solution? j Link to comment https://forums.phpfreaks.com/topic/136707-simple-regex-problem/#findComment-713948 Share on other sites More sharing options...
.josh Posted December 12, 2008 Share Posted December 12, 2008 $string = '<font face="Book Antiqua"><font size="5"><font color="Orange">asdasdasdasd</font></font></font>'; echo preg_replace('/(<font[^>]*>)<font size="(\d)">(<font.*\/font>)<\/font>(<\/font>)/',"$1[size=$2]$3[/size]$4",$string); Link to comment https://forums.phpfreaks.com/topic/136707-simple-regex-problem/#findComment-714009 Share on other sites More sharing options...
Caesar Posted December 12, 2008 Share Posted December 12, 2008 Even a better idea...CSS: #techcone { font-size: 11px; color: #FF9900; font-family: book antiqua; } <html> <head> <title>More Cowbell</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="robot" content="index, follow" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="techcone"> The font size, color and font family have been defined in your CSS!! </div> </body> </html> Now....if you are trying to make it dymaic (Your example code isn't clear, as you're using a non HTML tag), you'd use a different method. But you can even use a dynamic style sheet for that as well. Link to comment https://forums.phpfreaks.com/topic/136707-simple-regex-problem/#findComment-714013 Share on other sites More sharing options...
techcone Posted December 12, 2008 Author Share Posted December 12, 2008 Actually I am making a html to bbcode converter , if its not already made. The above tags are of bbcode. Link to comment https://forums.phpfreaks.com/topic/136707-simple-regex-problem/#findComment-714097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.