Status
Not open for further replies.

JmZ

(╯°□°)╯︵ ┻━┻
1,789
2008
729
0
Code:
[COLOR=#000000][FONT=Times New Roman][COLOR=#ff0000][FONT=monospace][COLOR=#999999]<?php[/COLOR]
    [COLOR=#770088][B]class [/B][/COLOR][COLOR=black]JString [/COLOR][COLOR=blue]{[/COLOR]
        [COLOR=#770088][B]private [/B][/COLOR][COLOR=black][B]$string [/B][/COLOR][COLOR=blue]= [/COLOR][COLOR=#aa2222][B]""[/B][/COLOR][COLOR=blue];[/COLOR]
    
        [COLOR=#770088][B]public [/B][/COLOR][COLOR=#770088][B]function [/B][/COLOR][COLOR=black]__construct[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$str[/B][/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]{[/COLOR]
            [COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string [/COLOR][COLOR=blue]= [/COLOR][COLOR=black][B]$str[/B][/COLOR][COLOR=blue];[/COLOR]
        [COLOR=blue]}[/COLOR]
        
        [COLOR=#770088][B]public [/B][/COLOR][COLOR=#770088][B]function [/B][/COLOR][COLOR=black]uri[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$sep[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=#aa2222]'-'[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]{[/COLOR]
            [COLOR=green][B]return [/B][/COLOR][COLOR=green]trim[/COLOR][COLOR=blue]([/COLOR][COLOR=green]preg_replace[/COLOR][COLOR=blue]([/COLOR][COLOR=#aa2222]'#[^\w\-]+#'[/COLOR][COLOR=blue], [/COLOR][COLOR=black][B]$sep[/B][/COLOR][COLOR=blue], [/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue])[/COLOR][COLOR=blue], [/COLOR][COLOR=black][B]$sep[/B][/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
        [COLOR=blue]}[/COLOR]
        
        [COLOR=#770088][B]public [/B][/COLOR][COLOR=#770088][B]function [/B][/COLOR][COLOR=black]uc[/COLOR][COLOR=blue]([/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]{[/COLOR]
            [COLOR=green][B]return [/B][/COLOR][COLOR=green]ucwords[/COLOR][COLOR=blue]([/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
        [COLOR=blue]}[/COLOR]
        
        [COLOR=#770088][B]public [/B][/COLOR][COLOR=#770088][B]function [/B][/COLOR][COLOR=black]truncate[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$len[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=#228811]15[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]{[/COLOR]
            [COLOR=green][B]return [/B][/COLOR][COLOR=green]strlen[/COLOR][COLOR=blue]([/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]> [/COLOR][COLOR=black][B]$len [/B][/COLOR][COLOR=blue]? [/COLOR][COLOR=green]substr[/COLOR][COLOR=blue]([/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue], [/COLOR][COLOR=#228811]0[/COLOR][COLOR=blue], [/COLOR][COLOR=black][B]$len[/B][/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]. [/COLOR][COLOR=#aa2222]'...' [/COLOR][COLOR=blue]: [/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue];[/COLOR]
        [COLOR=blue]}[/COLOR]
        
        [COLOR=#770088][B]public [/B][/COLOR][COLOR=#770088][B]function [/B][/COLOR][COLOR=black]advtrunc[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$words[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=#228811]10[/COLOR][COLOR=blue], [/COLOR][COLOR=black][B]$len[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=#006400][B]NULL[/B][/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]{[/COLOR]
            [COLOR=#770088][B]if[/B][/COLOR][COLOR=blue]([/COLOR][COLOR=green]strpos[/COLOR][COLOR=blue]([/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue], [/COLOR][COLOR=#aa2222]' '[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]=== [/COLOR][COLOR=#228811]false[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]{[/COLOR]
                [COLOR=#770088][B]if[/B][/COLOR][COLOR=blue]([/COLOR][COLOR=green][B]empty[/B][/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$len[/B][/COLOR][COLOR=blue])[/COLOR][COLOR=blue])[/COLOR]
                    [COLOR=green][B]return [/B][/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue];[/COLOR]
                [COLOR=#770088][B]else[/B][/COLOR]
                    [COLOR=green][B]return [/B][/COLOR][COLOR=green]strlen[/COLOR][COLOR=blue]([/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]> [/COLOR][COLOR=black][B]$len [/B][/COLOR][COLOR=blue]? [/COLOR][COLOR=green]substr[/COLOR][COLOR=blue]([/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue], [/COLOR][COLOR=#228811]0[/COLOR][COLOR=blue], [/COLOR][COLOR=black][B]$len[/B][/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]. [/COLOR][COLOR=#aa2222]'...' [/COLOR][COLOR=blue]: [/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue];[/COLOR]
            [COLOR=blue]}[/COLOR]
            [COLOR=#770088][B]if[/B][/COLOR][COLOR=blue]([/COLOR][COLOR=green]str_word_count[/COLOR][COLOR=blue]([/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]<= [/COLOR][COLOR=black][B]$words[/B][/COLOR][COLOR=blue])[/COLOR]
                [COLOR=green][B]return [/B][/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue];[/COLOR]
            [COLOR=black][B]$estring [/B][/COLOR][COLOR=blue]= [/COLOR][COLOR=green]explode[/COLOR][COLOR=blue]([/COLOR][COLOR=#aa2222]' '[/COLOR][COLOR=blue], [/COLOR][COLOR=#770088][B]$this[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]string[/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
            [COLOR=green][B]return [/B][/COLOR][COLOR=green]implode[/COLOR][COLOR=blue]([/COLOR][COLOR=#aa2222]' '[/COLOR][COLOR=blue], [/COLOR][COLOR=green]array_slice[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$estring[/B][/COLOR][COLOR=blue], [/COLOR][COLOR=#228811]0[/COLOR][COLOR=blue], [/COLOR][COLOR=black][B]$words[/B][/COLOR][COLOR=blue])[/COLOR][COLOR=blue]) [/COLOR][COLOR=blue]. [/COLOR][COLOR=#aa2222]'...'[/COLOR][COLOR=blue];[/COLOR]
        [COLOR=blue]}[/COLOR]
    [COLOR=blue]}[/COLOR]
    
    [COLOR=#aa7700]// Testing[/COLOR]
    [COLOR=green][B]echo [/B][/COLOR][COLOR=#aa2222]'<pre>'[/COLOR][COLOR=blue];[/COLOR]
        [COLOR=black][B]$jmz [/B][/COLOR][COLOR=blue]= [/COLOR][COLOR=#770088][B]new [/B][/COLOR][COLOR=black]JString[/COLOR][COLOR=blue]([/COLOR][COLOR=#aa2222]'so its like 4:30am here and i figured id throw up some random code for the public for once, who knows who will use it.'[/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
    [COLOR=green]var_dump[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$jmz[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]uri[/COLOR][COLOR=blue]([/COLOR][COLOR=blue])[/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
    [COLOR=green]var_dump[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$jmz[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]uc[/COLOR][COLOR=blue]([/COLOR][COLOR=blue])[/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
    [COLOR=green]var_dump[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$jmz[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]truncate[/COLOR][COLOR=blue]([/COLOR][COLOR=blue])[/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
    [COLOR=green]var_dump[/COLOR][COLOR=blue]([/COLOR][COLOR=black][B]$jmz[/B][/COLOR][COLOR=blue]->[/COLOR][COLOR=black]advtrunc[/COLOR][COLOR=blue]([/COLOR][COLOR=blue])[/COLOR][COLOR=blue])[/COLOR][COLOR=blue];[/COLOR]
    [COLOR=green][B]echo [/B][/COLOR][COLOR=#aa2222]'</pre>'[/COLOR][COLOR=blue];[/COLOR]
[COLOR=#999999]?>
[/COLOR][/FONT][/COLOR][/FONT][/COLOR]


EDIT:

FYI...
uri() - Format the string so it is safe for use in an SEO URI
uc() - Upper case the first letter of each word
truncate() - ... the string if it is too long
advtrunc() - ... the string and/or remove words if there are too many words or it is too long
 
13 comments
Output:
string(117) "so-its-like-4-30am-here-and-i-figured-id-throw-up-some-random-code-for-the-public-for-once--who-knows-who-will-use-it"
string(118) "So Its Like 4:30am Here And I Figured Id Throw Up Some Random Code For The Public For Once, Who Knows Who Will Use It."
string(18) "so its like 4:3..."
string(49) "so its like 4:30am here and i figured id throw..."
 
It's a nice and simple class. Useful and slightly more efficient to what I currently have.

This sorta work deserves the coder rank :P
 
He was a coder, if i recall correct btw he wasted it by being dis-respectful to staff an members in cb...

So jus cos he posted some smart ass php code, doesnt mean he deserves it bk.
 
Totally awesome Jmz, this is like pure epic pwnage, what am I too drunk to see that you are a regular member, damn I must really be too drunk lolwut

Nigga please :D
 
Status
Not open for further replies.
Back
Top