10 hours of PHP
Published Monday May 10th, 2004

Weee! I'm exhausted!

I spent all of sunday programing. From after eating lunch at around 1330 i programmed php non-stop untill dinner at 1830. Matt came over and picked up his Battlefield 1942 CD's around dinnertime. After dinner, i continued untill around 2345, around a total of 10 hours. Weee! Haha. I spent way too much time on the same few lines of code in one single function which i was working on. The sql-driven text-replace function was much more difficult to get working than it should have been. I must have had a huge mental mind block, or something of the sort, because it took me forever to finally get a working concept worked out and in place. I must have tried at least 5 different approaches of which none worked, untill i finally got ... this:

- - functions/blog_post_process.inc - -
<?php

//function performs text-replace type routines on text.
function blog_details_people($text){
    global 
$link$sqllink=$link;
    if (
$sqllink==""){
        
$sqllink=mysql_connect("localhost","omited","omited");    
        if (!
$sqllink){die("Couldn't connect to MySQL");}
        
mysql_select_db("omited",$sqllink) or die("Error".mysql_error());
    }
    
// Get all parent name/text key's.
    
$data=mysql_query("SELECT * FROM blog_details_people WHERE parent='1' AND name!='SPECIAL'");
    while (
$row=mysql_fetch_array($data)){
        
$disclaimer="[$row[id]-rep-a]";
        
$len=strlen($disclaimer);
        
$disclaimer2="[$row[id]-rep-/a]";
        
$len2=strlen($disclaimer2);        
        
// Get all sibling name/text key's for current parent.
        
$data2=mysql_query("SELECT * FROM blog_details_people WHERE link='$row[id]' ORDER BY seek_pattern ASC");
        while (
$row2=mysql_fetch_array($data2)){
                if (
$row2[replace]==""){$row2[replace]=$row2[key];}
                
// Mark positions for url/text insertion.
                
$text=str_replace(ucwords($row2[key]), "[$row[id]-rep-a]".ucwords($row2[replace])."[$row[id]-rep-/a]"$text);
                
$text=str_replace(strtoupper($row2[key]), "[$row[id]-rep-a]".ucwords($row2[replace])."[$row[id]-rep-/a]"$text);    
                
$text=str_replace($row2[key], "[$row[id]-rep-a]".ucwords($row2[replace])."[$row[id]-rep-/a]"$text);    
                
// Remove double position markers (Ex: key pair: John Doe and John results in (assuming $row[id]=01) [01-rep-a][01-rep-a]John[01-rep-/a] Doe[01-rep-/a]
                
while (strstr($text,"[$row[id]-rep-a][$row[id]-rep-a]")){
                    
$text_tmp=substr($text,0,strpos($text,"[$row[id]-rep-a][$row[id]-rep-a]"))."[$row[id]-rep-a]".ucwords($row2[replace])."".substr($text,strpos($text,"[$row[id]-rep-a][$row[id]-rep-a]")+$len+$len+strlen($row2[replace])+$len2);
                    
$text=$text_tmp;
                }
        }
        
// remove mis-replaced text-replacement position markers.
        
$data3=mysql_query("SELECT * FROM blog_details_people WHERE name='SPECIAL' AND summary='NO-REPLACE'");
        while (
$row3=mysql_fetch_array($data3)){
            
// seek from key to right. Mis-replaced word -> additional_index. EX: matter (conflict: Matt)
            
if ($row3[seek_pattern]==0){$text=str_replace("[$row[id]-rep-a]".ucwords($row3[website_url])."[$row[id]-rep-/a]$row3[blog_url]""$row3[replace]"$text);}
            
// seek from left to key. additional_index -> Misplaced word. EX: D'Andrea (conflict: Andrea)
            
elseif ($row3[seek_pattern]==1){$text=str_replace("$row3[website_url][$row[id]-rep-a]".ucwords($row3[blog_url])."[$row[id]-rep-/a]""$row3[replace]"$text);}
        }
        
// Replace position marker's with text/html-url.
        
$text=str_replace("[$row[id]-rep-a]""<a href=\\"http://marco.luethy.net/weblog/details/$row[id]-$row[key].html\\">"$text);
        
$text=str_replace("[$row[id]-rep-/a]""</a>"$text);
    }
    
// Perform additional, special text-replacement tasks.
    
$data4=mysql_query("SELECT * FROM blog_details_people WHERE name='SPECIAL' AND summary='HTML'");
    while (
$row4=mysql_fetch_array($data4)){
        
$text=str_replace("$row4[key]""$row4[replace]"$text);
    }    
    return 
$text;
}


?>


Heh... Way too much time was spent on those lines there.. Although, those very lines were rewriten a good 5 times. The hardest thing, for some reason, was handling double-replacements, simply because i couldnt think right and get the right concept in place. I'd search for Marco Luethy, and then, my function would go through and then, while still searching, find Marco again, and replace both with URL's which created problems with the HTML on the page. A page being linked twice, then closed and closed again. Then, dealing with words like 'awesome' where, the text 'wes' was found by my function, and replaced with a url, so that the word ended up being 'aWESome', more or less. Heh, i'm probably not really making much sense to anyone but myself, which is fine.

Anyway, i added a sort of "details" page, so now every name will most likely be linked to a page, where i have a little summary on the person, and their homepage, and blog linked. Additionally, if you don't want your full name shown on the site, let me know so that i can change it.

Heh, i made a lot of other internal additions to my blog's over all code. Woo. I'm happy. I haven't coded PHP for this long, straight in one push for a very long time. Feel's kind of good, though, im really exhausted. Thinking hurts. It's also tiring. Hmph.

Heh, it's another week of school coming up. Not really looking forward to it. Econ test on Friday, though, not much to worry about there. Beyond that, i dont really have anything planned at all. A lot of nothingness, so far. Heh

Anyway, I don't really have much more to say, so now, i think im going to do something relaxing. I havent watched TV in a very long time, perhaps ill do some of that, or, play a game on my laptop, just listen to music, something, i dunno. I'll probably go to bed around 0200. Heh, anyway..
Posted by DI @ 15:37, May 12, 2004
yayza for....stuff? lol i dunno
Reply