Page 1 of 1

Parsing page content - is it a bad idea?

Posted: Fri May 01, 2009 8:47 pm
by onyxmoron
Right now, my pages are made up of standard headers and footers, with variable content in the middle that comes from external html files that are included on the page.

I was thinking of ways to create a "glossary" effect. Originally I thought about having a script automatically insert links to certain phrases as the page loads (not adding them to the original source file), but after thinking more that might not work so well. Next I thought to use "markup", like wikipedia's [[link|text to display]] format. The script would use "link" to construct a link tag and attach it around the text, unless there's no entry for that term, in which case it would just show the text normally. This way when an entry for that term was eventually added, every instance of the maked-up term would turn into a link.

But to do this, instead of just "include"ing the content files like it does now, it would load the file into a variable, run preg_match to find all occurrences of the markup, go through the result array to find out if a matching entry exists for each thing, construct links for the ones that do, then preg_replace on the content to replace all occurrences of the markup with either the linked version or of the stripped "plain" version.

Would this be too taxing on the server to do this for the content of ever page every time someone wants to look at it? Some of the pages are 15kb+, and maybe someday there will be even bigger ones. Is there a better way to do this? Would it be better to have it create new files with the parsed content and just include them normally?

Re: Parsing page content - is it a bad idea?

Posted: Fri May 01, 2009 8:56 pm
by it2051229
yeah, you could do that one...

the other solution i can think of so that not to overload the server is to make use of javascript.
If you observe these websites that after you have visit them, some words automatically becomes a link? yeah like wikipedia.
I noticed that after loading the page, all the text are displayed first without links. After all the text are displayed, then it becomes a link.
So i was thinking, that's not possible if PHP alone does that.. Because if it's PHP alone, then while the page is loading the text is being processed on the server and it should have already been a link. But like i said, it only became a link after the page has been completely loaded, so i was thinking again, that they
made use of javascript that after the page has completely loaded, javascript will get the keywords from the server and javascript does the parsing. We know that javascript is executed on the client side and not on the server side. So you'll see that the parsing or processing is done on the client and not on the server which therefore reduces the processing load on the server.