Results 1 to 2 of 2

Thread: Beginner Projects

  1. #1

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    629

    Beginner Projects

    Hi today i started to learn some php for the first time here are 3 little projects i made a Text Counter, Graphic counter and a Randdom banner hope you find them usfull. also like to here from anyone that looks at the code if i can do it better as i only started today so i like to know were i can inprove.
    Attached Files Attached Files

  2. #2

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    629

    Re: Beginner Projects

    hi this is some basic code for a beginner to use comments suggestions welcome.

    ROT13

    PHP Code:
    <?php

    /**
     * @author Ben Jones
     * @name Rott13 Encoder/Decoder
     * @version 1.0
     * @license FreeForAll
     */

    function crypt13($source)
    {
        for (
    $x 0$x strlen($source); $x++) {
            
    //Get char.
            
    $c $source[$x];
            
    //Get byte.
            
    $b ord($source[$x]);

            
    //Encrypt.
            
    if (($c >= "A") and ($c <= "M") or ($c >= "a") and ($c <= "m")) {
                
    $b += 13;
            }
            
    //Decrypt.
            
    if (($c >= 'N') and ($c <= 'Z') or ($c >= 'n') and ($c <= 'z')) {
                
    $b -= 13;
            }
            
    //Build the string.
            
    $buf .= chr($b);
        }
        
    //Return result.
        
    return $buf;
    }

    //Example.
    $s "Hello to all coders.";
    $e crypt13($s);

    echo 
    "Original: " $s;
    echo (
    "</br>");
    echo 
    "Encoded: " $e;
    echo (
    "</br>");
    echo 
    "Decoded: " crypt13($e);

    ?>
    Proper case

    PHP Code:
    <?php
    /**
     * @author Ben Jones
     * @name ProperCase
     * @version 1.0
     */

    function ProperCase($source)
    {
        
    $source strtolower($source);
        
    //Break string into array.
        
    $ary explode(" "$source);

        for (
    $x 0$x <= sizeof($ary); $x++) {
            
    $temp $ary[$x];
            
    //Build the string.
            
    $line .= strtoupper($temp[0]) . substr($temp1) . " ";
        }
        return 
    $line;
    }

    //Example
    echo ProperCase("hello worLd this is a test string of title case.");
    ?>
    Last edited by BenJones; Aug 23rd, 2013 at 03:38 PM. Reason: Update

Posting Permissions

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



Click Here to Expand Forum to Full Width