Women in Technology

Hear us Roar



Article:
  Autofilled PHP Forms
Subject:   HTML parsing
Date:   2006-03-16 19:16:54
From:   mpeters
I'm not a PHP guy, but I know that parsing HTML with regular expressions is asking for problems. Does PHP not have any decent HTML parsers?


In Perl we use HTML::FillInForm, which is much more generic and uses HTML::Parser behind the scenes to handle all the oddities of HTML and do it very fast. It's as easy as:



HTML::FillInForm->new->fill(
file => 'blah.html',
fdat => { email => 'me@test.com' },
);


And with HTML::FillInForm::LibXML being written, it will use the libxml C library to make it blazingly fast.

Full Threads Newest First

Showing messages 1 through 2 of 2.

  • HTML parsing
    2006-03-16 19:29:31  GavinAndresen [View]

    PHP's got several HTML parsers (I mention HTML_Sax in the article); I used regular expressions instead because:

    1) All the full-blown HTML parsers have dependencies on other stuff, and the more dependencies the more pain for me (we deploy our code at LOTS of different ISPS, with lots of different PHP/Apache/IIS configurations).

    2) The HTML parsers assume your form is HTML. We use Smarty templates instead of raw HTML, and I use the same code to populate the form with either Smarty template variables or values from $_REQUEST.

    • HTML parsing
      2006-06-07 11:52:56  sbrown29 [View]

      Thank you so much. I had been looking for a form that redisplayed my form with the errors. In addition I wanted to email the form. I'm using this statement but it's not working
      "$firstname = $values['fname']; echo $firstname". fname is a fieldname in the parent form. For some reason $firstname is always blank. Any suggestions?