php function/class needed to validate html

Discussion in 'PHP' started by JEET, Jun 29, 2008.

  1. #1
    Hi,
    I need a function/class to validate a piece of html code. Like if my html is:
    $h='
    <P><A HREF=URL_HERE> some text </A> other normal text <FONT FACE="arial"> More Text </FONT></P>
    ';
    then that function/class would convert it to validate html
    For example there's no " sign in the href tag, and it's in uppercase. The entire font tag needs to be dropped and replaced with <span> may be...
    There could be more attributes inside the font tag, and all need to be replaced with <span> and style. Like:
    <FONT SIZE=4 FACE="arial"> More Text </FONT>
    Can anyone do this, or if there's a class/function already available, then please point me to it. :)
    Thanks :)
     
    JEET, Jun 29, 2008 IP
  2. clarky_y2k3

    clarky_y2k3 Well-Known Member

    Messages:
    114
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    108
    #2
    I'd advise you to have a look at the HTML tidy extension (php.net/tidy). You can find lots of good information at devzone.zend.com/node/view/id/761.
     
    clarky_y2k3, Jun 29, 2008 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Thanks for that, but that extension may not be available on some servers. This is needed for a freely redistributable script. :) Anything else I can use?
    Thanks :)
     
    JEET, Jun 29, 2008 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    I can write for you a class that can do what you want, but it's cost $ lol.

    Cheers.
     
    php-lover, Jun 29, 2008 IP
  5. clarky_y2k3

    clarky_y2k3 Well-Known Member

    Messages:
    114
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    108
    #5
    How complex is the HTML going to be? How many tags are there going to be? What tags will there be?
     
    clarky_y2k3, Jun 29, 2008 IP
  6. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #6
    Most of the tags will be:
    <P>, <A HREF></A>,<FONT SIZE FACE COLOR></FONT>,<IMG SRC>,<TABLE WIDTH VALIGN CELLSPACING CELLPADDING BORDER><TR><TD WIDTH VALIGN></TD></TR></TABLE>. Apart from these, BACKGROUND attribute at different places like inside <TD background=>
    The values of attributes can be inside "" sign, or without those. Like:
    <A HREF="URL"></A> OR <A HREF=URL></A>. There could be more like these in background, src etc...

    Thanks :)
     
    JEET, Jun 29, 2008 IP