Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

getMeaningfulContent() [PHP] - Search Engine

Name: Anonymous 2007-09-27 6:43 ID:x5s6Nq2a

i Have just written this function in php. It is a small part of a search engine, the function searches through a string (in this case it's the content field of a page) and attempts to pick chunks of text out of the string and join them using ...

This is similar to how google works although i'm sure their algorithm is more advanced than this 5 minute job.

NOTES: getMeaningfulContent($s = string, $k = keywords (string|array), $n = int (number of characters to seek))

<?php
function getMeaningfulContent($s, $p, $n = 250) {
    if (strlen($s) > $n) {
        $buffer = '';
        $t_end = strlen($s)-1;
        if (is_array($p)) {
            foreach ($p as $k=>$v) {
                $t_poz_start = strpos(strtoupper($s), strtoupper($v), 0);
                if ($t_poz_start !== false) { // we've found an occurence
                    $t_percentage_to_read = ($t_end - $t_poz_start) / count($p);
                    if (($t_poz_start + $t_percentage_to_read) >= $t_end) {
                        $buffer .= '...' . substr($s, $t_poz_start, $t_end-$t_poz_start);
                    }
                    else {
                        $buffer .= '...' . substr($s, $t_poz_start, $t_end);
                    }
                }
            }
        }
        else {
            $t_poz_start = strpos(strtoupper($s), strtoupper($p), 0);
            if ($t_poz_start !== false) { // we've found an occurence
                if ($t_end - $t_poz_start > 150) {
                    $buffer = substr($s, $t_poz_start, $t_end-$t_poz_start);
                }
                else { $buffer = substr($s, $t_poz_start, $t_end); }
            }
        }
        return $buffer;
    }
    else { return $s; }
   }
?>

Name: Anonymous 2007-09-27 7:19 ID:Heaven

Perl isn't ugly, i'm sorry but you FAIL.

Beauty is in the eye of the beholder, and combining PHP's syntax with it's feature richness and rapid development makes it a TOP BOWLER!

I would use it over lisp|python|prolog|haskell for it's major purpose.

And that is web development, and web development alone. If you want to create gtk apps or command line applications you can, but it's intended use is still web development, and at that task it excels.

Don't believe me? Well then you had better have a stacked deck or a couple of pairs up your sleeve because no amount of superficial ah hominen's (in b4 incorrect usage) will result in it's image as anything less than savior of modern day web development.

We all know that PHP was infested with bloat and fail long before perl came and kicked it's ass

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List