Monty: Whaddya mean she ain't my wife? Mal: She ain't your wife... cause she's married to me.

'Trash'


Buffistas Building a Better Board  

Do you have problems, concerns or recommendations about the technical side of the Phoenix? Air them here. Compliments also welcome.

To-do list


Rob - Nov 27, 2002 9:00:13 pm PST #1735 of 10000

Since none of the young whippersnappers seem to want to answer, this old fogey will take a shot.

I'd write the parse method to return the form content plus any tags needed to close unclosed tags. For extra credit, I'd add another method that returns whether the last call to parse had to add any tags. The latter method could be used if we decide to tell users that they are forgetting to close a tag.

I like this api slightly better because if you end up having to rewrite the middle portion of the form contents, you can do it. If you just return a list of tag closers, you're limited to fixing problems that can be fixed just by appending stuff. Which won't work if we try to attack the attribute quoting problem.


John H - Nov 27, 2002 9:05:22 pm PST #1736 of 10000

That makes sense, so we have a method which is

something.parse()

and it returns parsed/fixed content, and we have another one which is

something.neededFixing()

which returns true or false?

Or do we need a "something.parse()" which returns two things, the content and the boolean for neededFixing?


Rob - Nov 27, 2002 9:10:41 pm PST #1737 of 10000

Either works, having two separate functions is easier, unless PHP provides some wait of returning two separate return values to a single function.

in C++, it might be

pair<bool,string> parse(const string& formContent);

but I don't know how to do that in PHP.

When I get back home I'm going to learn how to use PHP. Maybe I'll take on one of those new features people want as a learning exercise.


John H - Nov 27, 2002 9:24:40 pm PST #1738 of 10000

having two separate functions is easier

That makes sense, but also means the whole routine has to be run again, just to get a true or false value.

unless PHP provides some wait of returning two separate return values to a single function

I don't see why not. You can return more than one thing, surely? Now I'm not sure. I'll go and check.


§ ita § - Nov 27, 2002 9:26:59 pm PST #1739 of 10000
Well not canonically, no, but this is transformative fiction.

The simplest thing to do would be to return an array.


John H - Nov 27, 2002 9:48:54 pm PST #1740 of 10000

I just about got there in another window.

I'm trying to return an array with either "true", "false" or "error" as the first arg, and the fixed content as the second.


John H - Nov 27, 2002 10:07:41 pm PST #1741 of 10000

OK have a look at this page: [link] which returns

  • the fixed content and a message to say it needed fixing,
  • unfixed content with a message to say it didn't, or
  • an error, of which there is only one type, "no content found to parse".


Rob - Nov 27, 2002 10:20:54 pm PST #1742 of 10000

John, looks good.

Here's what we should do for extra safety: run this function over every message already in the database, and log any that come back different. There should only be a small number of them. Someone should look at each one that comes back different and decide if it's a problem in the message in the database or a problem with the tag closer.

If the tag closer works correctly on all the old messages, I doubt it will fail on the new ones.


John H - Nov 27, 2002 10:32:11 pm PST #1743 of 10000

I've turned the whole thing into a function in this iteration by the way, so that you can just go

$results = array();

$results = parse_html($formcontent);

so what more do I need to do to make it OO?

I do

class Parser {

 function parse_html(){
  [code code code]
 }
}

then call on it with

$sweetLumpyParsingMinion = new Parser;
$sweetLumpyParsingMinion->parse_html($post);

or something like that?

If I only have one function, it seems like overkill.


§ ita § - Nov 27, 2002 10:38:24 pm PST #1744 of 10000
Well not canonically, no, but this is transformative fiction.

The structure for the code to date is that if there's no associated data structure, the function just goes in a general file. However, this will be applied to posts, right? So it would be a method of the post class.