HartleySan Posted June 11, 2011 Share Posted June 11, 2011 I have an HTML question. Wasn't sure where else to put it, so I'm posting it here. Anyway, this might sound like a silly question, but I want to be able to literally display HTML entities on an HTML page. For example, I want to be able display < on an HTML page instead of <. Does anyone know how to do this? Thank you. Link to comment Share on other sites More sharing options...
Stuart Posted June 11, 2011 Share Posted June 11, 2011 It's not something I've ever had to do but this works: echo htmlspecialchars(htmlspecialchars('&')); OR echo htmlspecialchars('&'); There might be another way but like I said never had to do it before. Link to comment Share on other sites More sharing options...
HartleySan Posted June 11, 2011 Author Share Posted June 11, 2011 And what if I'm using just plain ol' HTML? Link to comment Share on other sites More sharing options...
Antonio Conte Posted June 11, 2011 Share Posted June 11, 2011 A little CSS-hacking perhaps? HTML: &<span class="hide">.</span>lt; CSS: span.hide { display: none; // possibly more code. } < will always be encoded to < by the browser I think. This method might work because it's split up by punctuation. Not tested though Edit: If the text does not need to be markable by mouse/etc, you might just use a picture? Link to comment Share on other sites More sharing options...
HartleySan Posted June 12, 2011 Author Share Posted June 12, 2011 Hmmm...okay. Thanks for the ideas. I wonder if I could enter an HTML comment in between an entity code or something. I scoured the Net, and could not find any definitive answer. I kept looking at the source code for sites using <, but it's not obvious. Well, I'll keep looking. And if nothing else, Antonio's idea works. Link to comment Share on other sites More sharing options...
Antonio Conte Posted June 12, 2011 Share Posted June 12, 2011 I don't know but how about something like content: "<" in CSS? I don't know, but the only other thing I can think of. http://htmldog.com/r...erties/content/ Btw. Html-comment is not a bad idea. Tried &<!--comment-->lt; ? Link to comment Share on other sites More sharing options...
HartleySan Posted June 12, 2011 Author Share Posted June 12, 2011 Thanks for that info. Actually, this all isn't really that big of a deal. Just surprised that there's no easy way to handle this in HTML. Link to comment Share on other sites More sharing options...
HartleySan Posted June 12, 2011 Author Share Posted June 12, 2011 Can't take credit for this idea, but I got a great suggestion from a friend: < I thought that was really clever. I think I'll go with that, unless someone has a better idea. Link to comment Share on other sites More sharing options...
Antonio Conte Posted June 12, 2011 Share Posted June 12, 2011 Best idea in my head by a mile. Seem "the right way" to do what you want. It'll also be correct without a stylesheet. The only reason why I've given this some thought, is that I find it interesting myself. As with you, I couldn't see a good easy way to do this. Link to comment Share on other sites More sharing options...
HartleySan Posted June 13, 2011 Author Share Posted June 13, 2011 Well, no reason to bash yourself. I had to outsource the idea to a friend that's quite good at HTML/CSS. So as you can see, I couldn't think of anything good either. Link to comment Share on other sites More sharing options...
Recommended Posts