The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Usefull PHP Functions

  1. #1

    Usefull PHP Functions

    Well I have a weeks holiday and im bored so I have decided to make a library of usefull PHP functions, so I want to know, what functions would you find usefull, so far I have some database management ones planned and also some user-basics one (allow users to type: 132,435,354.34 and still use it in maths.)

    So anyone have any suggestions

  2. #2
    Roman numeral one.

    I posted one in Python a while back that would go to arabic, but not the other direction.


    K-Emmys-06: Best Footer; and K-Emmys-06: Most Active Member

  3. #3

  4. #4

  5. #5

  6. #6
    use regex to grab metadata from a url. fill in the blanks.
    PHP Code:
    class MetaGrab {
        private 
    $url;
        private 
    $data;
        private 
    $keywords = array();
        private 
    $dscpn;
        private 
    $title;
        private 
    $author;
        private 
    $rss;
        private 
    $copyright;
        private 
    $css;
        
        function 
    __construct$url ) {
            
    $this->url $url;
            
    // blank
        
    }
        
        function 
    setData() {
            if( 
    $this->url != '' ) {
                
    $this->data file_get_contents$this->url );
            }
        }
        
        function 
    getData() {
            return 
    $this->data;
        }

        function 
    getKeywords() {
            
    // blank
            
    return $this->keywords;
        }
        
        function 
    getTitle() {
            
    // blank
            
    return $this->title;
        }
        
        function 
    getAuthor() {
            
    // blank
            
    return $this->author;
        }
        
        function 
    getRSS() {
            
    // blank
            
    return $this->rss;
        }
        
        function 
    getCopyright() {
            
    // blank
            
    return $this->copyright;
        }
        
        function 
    getCSS() {
            
    // blank
            
    return $this->css;
        }


  7. #7
    oh wait I think I know what metaData is now, ill start right on that bwh2..... right after I catch some sleep, then go to teh cinema tomorow.

  8. #8
    metadata is just everything within the <head> tags. it's actually not that difficult. it would be a good intro to regex. in this case, i only want certain data.

    oh yeah, and document your code in phpDocumentor style. this will get you started: http://manual.phpdoc.org/HTMLSmartyC...ng.phpcomments

  9. #9
    yeah, but I know how to get meta tags by just using: get_meta_tags()

    Wouldnt that be easier? although I do need to get better regex

  10. #10

  11. #11
    ok, thanks, I have a week of no-work or school work, so I just want to build up my PHP knowledge, and Nokrevs challenge wasnt much, oh and for him heres the code:
    PHP Code:
    <?php
    echo arabtoroman(2.5);
    function 
    romantoarab($value) {
    $value str_split($value);
        
    $total 0;
        
    $values = array(
            
    'I' => 1,
            
    'V' => 5,
            
    'X' => 10,
            
    'L' => 50,
            
    'C' => 100,
            
    'D' => 500,
            
    'M' => 1000
        
    );
        
    $prevValue 0;
        foreach (
    $value as $data) {
            if (
    $values[$data] > $prevValue) {
                
    $total -= $prevValue;
            } else {
                
    $total += $prevValue;
            }
            
    $prevValue $values[$data];
        }
        
    $total += $prevValue;
        return 
    $total;
    }
    function 
    arabtoroman($num) {
    if (
    $num || $num 9999) { 
    echo 
    'Out of range, to help improve this script contact me at stuart.loxton@googlemail.com';
    }
    $r_ones = array(1=> "I"2=>"II"3=>"III"4=>"IV"5=>"V"6=>"VI"7=>"VII"8=>"VIII"9=>"IX");
    $r_tens = array(1=> "X"2=>"XX"3=>"XXX"4=>"XL"5=>"L"6=>"LX"7=>"LXX"8=>"LXXX"9=>"XC");
    $r_hund = array(1=> "C"2=>"CC"3=>"CCC"4=>"CD"5=>"D"6=>"DC"7=>"DCC"8=>"DCCC"9=>"CM");
    $r_thou = array(1=> "M"2=>"MM"3=>"MMM"4=>"MMMM"5=>"MMMMM"6=>"MMMMMM"7=>"MMMMMMM"8=>"MMMMMMMM"9=>"MMMMMMMMM");
    $ones $num 10;
    $tens = ($num $ones) % 100;
    $hundreds = ($num $tens $ones) % 1000;
    $thou = ($num $hundreds $tens $ones) % 10000;
    $tens $tens 10;
    $hundreds $hundreds 100;
    $thou $thou 1000;
    if (
    $thou) { $rnum .= $r_thou[$thou]; }
    if (
    $hundreds) { $rnum .= $r_hund[$hundreds]; }
    if (
    $tens) { $rnum .= $r_tens[$tens]; }
    if (
    $ones) { $rnum .= $r_ones[$ones]; }
    return 
    $rnum;
    }
    ?>

  12. #12
    http://www.kirupa.com/forum/showthread.php?t=251143

    Damn it, you wasted my entire night. Thanks a lot.


    K-Emmys-06: Best Footer; and K-Emmys-06: Most Active Member

  13. #13
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Quote Originally Posted by nokrev View Post
    Damn it, you wasted my entire night. Thanks a lot.
    I know the feeling. I'm trying to work out something with regular expressions in Flash and it's taking a while. Although, technically, I guess I'm wasting my own time
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  14. #14
    I don't know much about regex in AS, but I know quite a bit about it in general. If you need help hit me up on msn. I'll be on tomorrow.

  15. #15
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Quote Originally Posted by blazes View Post
    I don't know much about regex in AS, but I know quite a bit about it in general. If you need help hit me up on msn. I'll be on tomorrow.
    Thanks for the offer It's not the regex itself I'm having a problem with however - just the logic behind what I'm trying to do. Regular expressions are probably the best thing since sliced bread.

    This is a pretty awesome thread, by the way
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012