mramardeepsingh Posted December 13, 2006 Share Posted December 13, 2006 hi friendsi want to know that how can i replace the entire content in <..............> tags.for examplei have a code<STRONG><I><B><FONT COLOR="red">Example Text</FONT></B></I></STRONG>and i want to convert the html tags to small caps without converting the text i.e Example Text.<STRONG> should be <strong><I> should be <i><FONT COLOR="red"> should be <font color="red">but keeping the text i.e Example Text intact.due to which i can't use strtolower.please tell me how to convert the html tags into smallcaps.what regular expression to use so that i get<strong><i><b><font color="red">Example Text</b></i></font></strong>thanksplease help Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/ Share on other sites More sharing options...
bbaker Posted December 13, 2006 Share Posted December 13, 2006 how 'bout using CSS?font-variant:small-caps; Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-140585 Share on other sites More sharing options...
HuggieBear Posted December 14, 2006 Share Posted December 14, 2006 This almost works...[code=php:0]<?php// Test html code$html = <<<HTML<HTML><HEAD><TiTlE>This is My Title</TITlE><body BG="Red"> This is Some Text</body></HtML>HTML;// Regular expressionecho preg_replace("/(<.*?>)/e", "''.strtolower('$1').''", $html);?>[/code] The problem is that it escapes all the single and double quotes in the output. Here's what it produces...[code]<html><head><title>This is My Title</title><body bg=\"red\"> This is Some Text</body></html>[/code]But it's a start.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-140966 Share on other sites More sharing options...
mramardeepsingh Posted December 15, 2006 Author Share Posted December 15, 2006 thanks huggiethanks for the help.i think this will workthanks again man Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-141869 Share on other sites More sharing options...
obsidian Posted December 15, 2006 Share Posted December 15, 2006 Huggie, you've got to be careful with your solution, because it will also change any attribute values to lowercase, and when you're referencing a URL, javascript function or a class/id for CSS, case sensitivity is in play. It's a great start, but you'll want to parse a bit further and make sure that nothing within single or double quotes is changed as well. Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-141883 Share on other sites More sharing options...
HuggieBear Posted December 16, 2006 Share Posted December 16, 2006 Good point Obs, didn't think of that.This will need a little more thought I think.Huggie Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-142372 Share on other sites More sharing options...
Switch0r Posted December 16, 2006 Share Posted December 16, 2006 why don't you just open the code in notepad, and find/replace any instances of the tags you want lowercase with the match case option on?Unless the code is not saved locally/user inputted online (?) Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-142439 Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 next question... html is non case specific, and if you just set your css/js to all lowercase too, who cares? or make the css/js seperate variables... Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-142441 Share on other sites More sharing options...
obsidian Posted December 18, 2006 Share Posted December 18, 2006 [quote author=taith link=topic=118504.msg486148#msg486148 date=1166281972]next question... html is non case specific, and if you just set your css/js to all lowercase too, who cares? or make the css/js seperate variables...[/quote]Because all lowercase in coding is very seldom best practice. When defining functions or other attributes of coding languages, there are often cases where camel-case (ie, myFunction) is the best practice. So, you never want to throw best practices out the window to work around a problem. You're much better off to find a solution that will work in conjunction with the best practices you have put in place. As for your comment about making the CSS and Javascript separate variables, I'm not sure I follow what you're after. Quote Link to comment https://forums.phpfreaks.com/topic/30541-how-to-convert-to-small-caps/#findComment-143538 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.