htmlspecialchars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

htmlspecialchars

Post by Vegan »

I noticed when Googling for a problem with my chess site, how to leverage PHP to convert the old format included file into something that will render fine with HTML 56 browsers

htmlspecialchars seems to be what I want

Code: Select all

<?php include $_SERVER["DOCUMENT_ROOT"] . "/tournaments/html/group1.html"; ?> <!-- Arena conveniently formats results -->
I tried

Code: Select all

echo htmlspecialchars(file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/tournaments/html/group1.html')); 
while the result was what I wanted, I wanted the table to draw, not the basic text shown,

what should I do to this include call to pass it through the converter?

so that the table shows properly?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htmlspecialchars

Post by requinix »

Don't use htmlspecialchars(). That's for when you want something to not be interpreted as HTML. The opposite of what you're trying to do.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: htmlspecialchars

Post by Vegan »

then what function should I use to clean up the imported HTML file that needs to be escaped
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htmlspecialchars

Post by requinix »

Nothing? What are you trying to "clean"? If it's your HTML then you shouldn't have to do anything to it...
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: htmlspecialchars

Post by Vegan »

The problem is there are some symbols that need to be escaped and they are not which is why I was searching for some kind of functionality

this way I can have the table look cleaner and as intended

even with UEF-8
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htmlspecialchars

Post by requinix »

You keep saying "escaped". Can you describe what problem you're trying to solve by "escaping"?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: htmlspecialchars

Post by Vegan »

an example might make it clear

let file.html contain some non UEF-8 characters that I want to massage into UTFT

http://www.theukwebdesigncompany.com/ar ... acters.php

the . character is AKA &#44; etc, so what I wanted to achive is to swap the problem symbols for the & etc

this way the page will render as wanted, hard coded so to speak
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htmlspecialchars

Post by requinix »

Why not just fix the problem in the file itself? Directly.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: htmlspecialchars

Post by Vegan »

unfortunately the program that emits the crappy HTML is not open source so I cannot do anything about it, except maybe parse it which is what I have been trying to figure out
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htmlspecialchars

Post by requinix »

Okay, well your description a couple posts up doesn't make much sense to me.

Is this a problem of character encoding? The file has characters in a known, non-UTF-8 encoding? Convert the string with iconv or mb_convert_encoding.
Is it messy HTML? Try applying Tidy to it.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: htmlspecialchars

Post by Vegan »

I ran across another PHP function that possibly has some potential??

utf8_encode(string) // this is what I want, then I can assemble from that???

http://www.w3schools.com/php/func_xml_utf8_encode.asp
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply