Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Lankiveil
Feb 23, 2001

Forums Minimalist
I'm trying to put together a text comparison tool, that will compare two strings (more than likely containing largish volumes of fulltext), and show the different, something like Wikipedia's diff functionality.

Doing a simple character-by-character comparison will not work, because the first "new" character in a string will push all the others forward, causing almost everything after that point to be highlighted. Tokenising the string seems to be the way forward, but I can't work out a good way of comparing that doesn't "match" completely unrelated words later on in the text.

Is there an accepted way of doing this, or am I going to need to invent some new kind of wheel?

Adbot
ADBOT LOVES YOU

Lankiveil
Feb 23, 2001

Forums Minimalist
I'm looking at implementing my own RSS feed generator, which will work off of a series of existing tables in my database. I had planned to simply write a PHP script that output the required XML straight to the client, but most of the tutorials that I've seen on the web do it by generating a flat text file at a regular interval and having that serve as the feed.

I had hoped to be able to do customisable feeds (ie: so the user can filter out particular contributors or topics and get a feed containing only that), but if I'm to generate flat files that will mean I'll need to do hundreds of them to cover every possibility. Is there some compelling reason why I can't just take a querystring (rewritten with mod_rewrite, of course) and spit the output directly to the user based upon the input parameters?

Lankiveil
Feb 23, 2001

Forums Minimalist

clockworkjoe posted:

Can someone confirm the site looks okay in firefox 3 beta?

Don't know about Firefox, but looks okay in Opera 9.27:

http://www.halo-17.net/iomha/upload/080602_2_raillery.png

Lankiveil
Feb 23, 2001

Forums Minimalist

fletcher posted:

You will probably want to implement some sort of cache so you can store the messages in memory rather than querying the DB for each message every time you use it.

In the past, I've created files that contain translation tables for each text element that I want translated:

php:
<?
// /languages/en.php

$lang->login = "Login";
$lang->logout = "Logout";
$lang->welcome = "Welcome";
// ...

// /languages/ga.php
$lang->login = "Logáil isteach";
$lang->logout = "Logáil amach";
$lang->welcome = "Fáilte!";
?>
Then, in my standard header code, I do something along the lines of:

php:
<?
// default language
require_once("languages/en.php");

// user preference language
require_once("languages/$userprefs->lang.php");
?>
This not only allows the user to choose whatever language they wish, it also provides a fallback to English or another default language if the translation is not complete for the language they want.

I've never done this for a site with more than a couple of dozen text elements though, and it's probably horribly inefficient for a site that has thousands of them.

Lankiveil
Feb 23, 2001

Forums Minimalist

drcru posted:

So I'm trying to implement Dijkstra's algorithm for a side project I'm working on but I'm having difficulty grasping how the whole thing works...

I've done this before but I don't have the code in front of me, so bear with me. But yes, I made the "sectors" or "room" the vertices and then had a separate table that acted as vertices/paths. The main drawback with my method was that one had to have the entire graph in memory, which was a bit of a downer when you only wanted to go across to the next node.

If you haven't got working code, this might help: http://en.giswiki.net/wiki/Dijkstra's_algorithm

Lankiveil
Feb 23, 2001

Forums Minimalist
What is the current cool framework to use for PHP? At the moment I'm playing with CodeIgniter, but I'm happy to jump ship if there's something better out there.

Lankiveil
Feb 23, 2001

Forums Minimalist

Anveo posted:

If you are going to look into it, you will probably want to start with version 1.2.

I've just had a quick look through the docs, and it actually looks fairly good. I'll have a bit of a play with this, thanks for the tip!

Lankiveil
Feb 23, 2001

Forums Minimalist

MrMoo posted:

Does anyone bother altering HTTP status codes for errors? Taking R1CH's upload script for example:

Yes, I use some obscure status codes (402 and 405, for instance) for things like malformed requests or unsupported requests. Perhaps not so useful for screenscrapers (who are the only ones who usually do these things), but useful for log tracking to see what bots are getting up to.

Lankiveil
Feb 23, 2001

Forums Minimalist
I've got some strings that need to be inserted into the database via an UPDATE command. However, the strings may or may not already be escaped (don't ask). For instance, I might have "don't go not don't" or "don/'t go not don/'t" passed to my module.

Is there any reliable way to make sure that apostrophes have only one slash, and are not double-slashed like in this thread title?

Adbot
ADBOT LOVES YOU

Lankiveil
Feb 23, 2001

Forums Minimalist

Supervillin posted:

Yep, do this to whatever your input variable is before you escape stuff yourself:
code:
$input = preg_replace('/\\\\+\'/', "'", $input);
That'll take care of previously escaped, double escaped, even quintuple escaped apostrophes, which you can then singly escape yourself.

Or if you want to unescape quotes and apostrophes:
code:
$input = preg_replace('/\\\\+(\'|")/', '\\1', $input);

Great, this looks like exactly what I'm after. Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply