FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Noobie's code





Ircher
This is mine; I copied and pasted it from a source document of mine.
Code:
<!-- Copyright 2013, May 30-June ?? by Ircher -->
<!-- This may be used referentially, but may not be explicitly copied. -->
<!-- Any questions, comments, modifications, or permission requests can be sent to http://ircher@gmail.com/. -->
<!-- This document may not be edited and redistrubed for money; you may not make explicit copies to sell. -->
<!-- You may keep a local and a backup copy of the source code on your computer and one copy on the server to use -->
<!-- and reference as you learn web design. -->
<!-- Any rights not granted hereby are reserved and NOT granted. -->

<!DOCTYPE html> <!-- This identifies the document type; what type it is and what version it is. It is recommended to be explicitly defined.-->

<html> <!-- This tells the browser that this code is HTML code and to parse it as such. -->
<!-- Multiple <html><head><body> and their end tags will result in an error, whether nested or not. -->

<head> <!-- This starts the head code. --> <!-- Most people put styles and code here. -->
<title>Website Fundamentals - Heavily commented CSS, HTML, JavaScript, and PHP code!</title>
<!-- Important - What is displayed in the header bar (see above line) eg. PHP Manual. -->

<!-- This is the way you write an html comment. It spans one line and must be terminated with two - and the greater than sign (no space.)-->
<!-- Html Comments can be multiple on a line --> <!-- There can also be a statement between comments close and open. -->

<!-- Comments in CSS are the same as JavaScript Multi-Line Comments..-->
<!-- This defines a css style that is assigned default if not explicitly specified. -->
<style type="text/css"> /* This is how you write a css comment. It can span more than one line, but to preserve the format, I'd rather not. */
   #echo {color:#00CCC6;} /* Items with the id of ' echo ' will be turquoise. */
   .js {color:#00CC00;} /* Items with the class of 'js' will be greeen. */
   .php {color:#0000C0;} /* Items with the class of 'php' will be blue. */
   .html {color:#FF0000;} /* Items with the class of 'html' will be red. */
   .css {color:#FF00CC;} /* Items with the class of 'css' will be purple. */
</style>
<!-- Note that ID's override classes which override normal html styles (eg. BODY{}).-->

<!-- By making the JavaScript look similiar to an html comment, we render it usable everywhere. -->
<!-- JavaScript is a client-side scripting language, so you can see the results immediately when you open the file, even on your computer! -->
<!-- JavaScript is case-sensitive, so var a & var A are the same! -->
<script type="text/JavaScript">
<!--
   // Below is my copyright information; please stick to it!
   /* Copyright 2013 May 30-June ??
      Publisher = Ircher
      Author     = Ircher
      Contact     = http://ircher@gmail.com/ */

   // This is a basic JavaScript Comment. It spans 1 line.
   /* This is an advanced JavaScript Comment.
       It spans more than 1 line.
       It is commonly referred to as a multi-line comment. */
   
   // We load the document, this event & function is fired!
   window.onload = function() {
      // Set a p1 to the element with the Id of 'para1'.
      var p1= document.getElementById("para1");
      var p1Text = p1.textContent; // Find the text content of p1 and set it to a new variable.
      p1.textContent = "This html content has been modified by JavaScript."; // Change the text content of p1.
      }
//-->
</script> <!-- JavaScript is by default script; it is used if type isn't explicitly specified.-->

<!-- PHP is a server-side scripting language, so you don't see the results immediately and you must test it on a server, unlike JavaScript.-->
<!-- We could've also used a '<?php' opening tag and a '?>' ending tag; however, the IE10 finds it an error, so I'm writing it like this. -->
<script language="php">
# Below is my copyright information.
# Copyright 2013 - All Rights Reserved except that as granted.
# Copyright of Ircher; Distributed and Published by Ircher.

# This is one way to write a comment; it spans a single line.
// This is another way to write a comment; it also spans a single line.
/* This is a third way to write a comment.
    It can span multiple lines.
    Double / and * slash are found in JavaScript Coding :). */
function xrange($start, $limit, $step = 1) {
# This is a generator. It increases performance for loops.
    if ($start < $limit) {
        if ($step <= 0) {
            throw new LogicException('Step must be +ve');
        }

        for ($i = $start; $i <= $limit; $i += $step) {
            yield $i;
        }
    } else {
        if ($step >= 0) {
            throw new LogicException('Step must be -ve');
        }

        for ($i = $start; $i >= $limit; $i += $step) {
            yield $i;return;
        }
    }
}

class phpClass1
{
# This is my first php Class; used for debugging and testing stuff.
   protected function __construct() {
   // This is ran when the class is initiallized or ' constructed '.
   // It can only be accessed via parent, descendent, or the current class (aka. ' protected ')

      // Set the value of variable $x to 10 and sets variable $y as $x - 10 or in other words, 0 in this case.
      // Variable $x may not be used by any classes except the class or function it is defined in.
      // Final Items cannot be overwritten.
      final private $x = 10
      protected $y = $x - 10
      // Basic while loop that loops until the condition is false (or true). May not be used in some cases.
      while (y<=x) {
         // Pre-increments y and then echos it to the browser/server.
         ++y; echo "The value of y is $y!";
      }
      // Reset the variable to its original value, so you can...
      // Return its value to other classes!
      $y = $x - 10
      return $y;
   }
}

class phpClass2 extends phpClass1
{
# Extends Protected & Public Functions, etc. to phpClass2 from phpClass1.
   protected function __construct() {
   // This is ran when the class is initialized.
   // It is protected.

      // Set $a as a protected variable equal to (((5*1+7) Bitwise &(5*3-7)) Bitwise | (or) 10).
      protected $a = (((5*1+7)&(5*3-7))|10)
      // Return $a for the phpPrototype Class.
      return $a;
   }
}

class phpPrototype extends phpClass2
{
# The prototype class; the prototype class is like the predecessor to the Base class defined later.
# It extends phpClass2 rather than phpExtendClass1 as phpBase does.
   public function __construct() {
   // This is ran when the class is created.
   // It is public and accessible by everything.

      // Set a public $e to the value of $a from the extended class
      public $e = (phpClass2::__construct)
      // Create an array of colors assigned to public $arrayColor
      public $arrayColor = array('White','Black','Red','Orange','Yellow','Blue','Purple','Turquoise','Pink','Brown','Gray')
      // Returns $e.
      return $e
   }
   Set a public variable,  $v, to 5.
   public $v = 5
}

class phpExtendClass1 extends phpClass1
{
# This class extends the class specified above.
   protected function __construct() {
   // This is ran when the class is constructed.
   // It is protected.

      // Set the value of $z to phpClass1's ($y value plus 2) multiplied by 3.
      // Note that the result would be the same without the parenthesis in this case.
      // Since $y = 0; in any other case where it didn't = 0, the parenthesis are neccessary.
      // To make sure the correct order is followed!
      final protected $z = ((phpClass1::__construct()) + 2) * 3 // Note that this would probably throw an error if $y was private.
      // Return a value for descendents.
      return $z
   }
}

class phpBase extends phpExtendClass1
{
# Like class phpExtendClass1 but extends it, and as the name implies, it will probably base other classes.
   private function __construct() {
   // This is ran when the class is constructed.
   // Only this class may access this function.

      // Set the value of $w to phpExtendClass1's ($z - phpClass1's ($y+5-(2*2)))
      final private $w = ((phpExtendClass1::__construct) - ((phpClass1::__construct)+5-(2*2))
      // Return $w for the next class function
      return $w
   }
   public function Base {
   // This is ran when called.
   // Anything can access this function.
      // Set $a to the value of $y
      public $a = (phpClass1::__construct)
      // Set $b to the value of $z
      public $b = (phpExtendClass1::__construct)
      // Set $c to the value of $w from initialize
      public $c = (phpBase::__construct)
      // Set $d to the value of the prototype class's $proto
      protected $d = (phpPrototype::__construct)
      // Return Nothing
      return NULL
   }
}
</script> <!-- This ends the PHP script. -->

<!-- If you wanted, you could put normal body text here; however, I won't be doing that. -->
</head> <!-- This terminates the head code. -->

<!-- Any plain text put here will be rendered in the body and may result in an error. -->

<body> <!-- This starts the body code. --><!-- Most people put actual things to display here. -->
<!-- Anything outside a tag will be rendered as plain text and thus, displayed as such. -->
<!-- However, it is unrecommended because that can lead to unusual problems and explicit definitions are more reliable and readable -->
<!-- Also, it is rendered as plain text and thus, cannot have a class or an id or a name. -->

<p class="html" id="para1">This is a sample text rendered as HTML.</p> <!-- This is a paragraph with the class "html" and id "para1". -->
<p class="js" id="para2">// This looks like a JS comment; however it is really just html.</p> <!-- This paragraph has class "js" and id "para2".-->

</body> <!-- This terminates the body code. -->

</html> <!-- This terminates the html code. -->


Yes, it is heavily commented, yes it is huge, yes, I'm submitting. So, what do you think; I'm a total noob at php and a beginner at JavaScript.
Peterssidan
Ircher wrote:
This is the way you write an html comment. It spans one line and must be terminated with two - and the greater than sign (no space.)

HTML comments can span multiple lines.

Ircher wrote:
JavaScript is case-sensitive, so var a & var A are the same!

JavaScript is case-sensitive, which means that var a; and var A; are not the same.

Ircher wrote:
We could've also used a '<?php' opening tag and a '?>' ending tag; however, the IE10 finds it an error, so I'm writing it like this.

If you have not configured the server to do otherwise, it will parse ' opening tag and a ' as PHP which will give you an error because it is not valid PHP.
Arrogant
There's a lot of comments. woof
Maybe more than the code itself
Qantas94Heavy
Ircher wrote:
This is mine; I copied and pasted it from a source document of mine.
Code:
<!-- Copyright 2013, May 30-June ?? by Ircher -->
<!-- This may be used referentially, but may not be explicitly copied. -->
<!-- Any questions, comments, modifications, or permission requests can be sent to http://ircher@gmail.com/. -->
<!-- This document may not be edited and redistrubed for money; you may not make explicit copies to sell. -->
<!-- You may keep a local and a backup copy of the source code on your computer and one copy on the server to use -->
<!-- and reference as you learn web design. -->
<!-- Any rights not granted hereby are reserved and NOT granted. -->

<!DOCTYPE html> <!-- This identifies the document type; what type it is and what version it is. It is recommended to be explicitly defined.-->

<html> <!-- This tells the browser that this code is HTML code and to parse it as such. -->
<!-- Multiple <html><head><body> and their end tags will result in an error, whether nested or not. -->

<head> <!-- This starts the head code. --> <!-- Most people put styles and code here. -->
<title>Website Fundamentals - Heavily commented CSS, HTML, JavaScript, and PHP code!</title>
<!-- Important - What is displayed in the header bar (see above line) eg. PHP Manual. -->

<!-- This is the way you write an html comment. It spans one line and must be terminated with two - and the greater than sign (no space.)-->
<!-- Html Comments can be multiple on a line --> <!-- There can also be a statement between comments close and open. -->

<!-- Comments in CSS are the same as JavaScript Multi-Line Comments..-->
<!-- This defines a css style that is assigned default if not explicitly specified. -->
<style type="text/css"> /* This is how you write a css comment. It can span more than one line, but to preserve the format, I'd rather not. */
   #echo {color:#00CCC6;} /* Items with the id of ' echo ' will be turquoise. */
   .js {color:#00CC00;} /* Items with the class of 'js' will be greeen. */
   .php {color:#0000C0;} /* Items with the class of 'php' will be blue. */
   .html {color:#FF0000;} /* Items with the class of 'html' will be red. */
   .css {color:#FF00CC;} /* Items with the class of 'css' will be purple. */
</style>
<!-- Note that ID's override classes which override normal html styles (eg. BODY{}).-->

<!-- By making the JavaScript look similiar to an html comment, we render it usable everywhere. -->
<!-- JavaScript is a client-side scripting language, so you can see the results immediately when you open the file, even on your computer! -->
<!-- JavaScript is case-sensitive, so var a & var A are the same! -->
<script type="text/JavaScript">
<!--
   // Below is my copyright information; please stick to it!
   /* Copyright 2013 May 30-June ??
      Publisher = Ircher
      Author     = Ircher
      Contact     = http://ircher@gmail.com/ */

   // This is a basic JavaScript Comment. It spans 1 line.
   /* This is an advanced JavaScript Comment.
       It spans more than 1 line.
       It is commonly referred to as a multi-line comment. */
   
   // We load the document, this event & function is fired!
   window.onload = function() {
      // Set a p1 to the element with the Id of 'para1'.
      var p1= document.getElementById("para1");
      var p1Text = p1.textContent; // Find the text content of p1 and set it to a new variable.
      p1.textContent = "This html content has been modified by JavaScript."; // Change the text content of p1.
      }
//-->
</script> <!-- JavaScript is by default script; it is used if type isn't explicitly specified.-->

<!-- PHP is a server-side scripting language, so you don't see the results immediately and you must test it on a server, unlike JavaScript.-->
<!-- We could've also used a '<?php' opening tag and a '?>' ending tag; however, the IE10 finds it an error, so I'm writing it like this. -->
<script language="php">
# Below is my copyright information.
# Copyright 2013 - All Rights Reserved except that as granted.
# Copyright of Ircher; Distributed and Published by Ircher.

# This is one way to write a comment; it spans a single line.
// This is another way to write a comment; it also spans a single line.
/* This is a third way to write a comment.
    It can span multiple lines.
    Double / and * slash are found in JavaScript Coding :). */
function xrange($start, $limit, $step = 1) {
# This is a generator. It increases performance for loops.
    if ($start < $limit) {
        if ($step <= 0) {
            throw new LogicException('Step must be +ve');
        }

        for ($i = $start; $i <= $limit; $i += $step) {
            yield $i;
        }
    } else {
        if ($step >= 0) {
            throw new LogicException('Step must be -ve');
        }

        for ($i = $start; $i >= $limit; $i += $step) {
            yield $i;return;
        }
    }
}

class phpClass1
{
# This is my first php Class; used for debugging and testing stuff.
   protected function __construct() {
   // This is ran when the class is initiallized or ' constructed '.
   // It can only be accessed via parent, descendent, or the current class (aka. ' protected ')

      // Set the value of variable $x to 10 and sets variable $y as $x - 10 or in other words, 0 in this case.
      // Variable $x may not be used by any classes except the class or function it is defined in.
      // Final Items cannot be overwritten.
      final private $x = 10
      protected $y = $x - 10
      // Basic while loop that loops until the condition is false (or true). May not be used in some cases.
      while (y<=x) {
         // Pre-increments y and then echos it to the browser/server.
         ++y; echo "The value of y is $y!";
      }
      // Reset the variable to its original value, so you can...
      // Return its value to other classes!
      $y = $x - 10
      return $y;
   }
}

class phpClass2 extends phpClass1
{
# Extends Protected & Public Functions, etc. to phpClass2 from phpClass1.
   protected function __construct() {
   // This is ran when the class is initialized.
   // It is protected.

      // Set $a as a protected variable equal to (((5*1+7) Bitwise &(5*3-7)) Bitwise | (or) 10).
      protected $a = (((5*1+7)&(5*3-7))|10)
      // Return $a for the phpPrototype Class.
      return $a;
   }
}

class phpPrototype extends phpClass2
{
# The prototype class; the prototype class is like the predecessor to the Base class defined later.
# It extends phpClass2 rather than phpExtendClass1 as phpBase does.
   public function __construct() {
   // This is ran when the class is created.
   // It is public and accessible by everything.

      // Set a public $e to the value of $a from the extended class
      public $e = (phpClass2::__construct)
      // Create an array of colors assigned to public $arrayColor
      public $arrayColor = array('White','Black','Red','Orange','Yellow','Blue','Purple','Turquoise','Pink','Brown','Gray')
      // Returns $e.
      return $e
   }
   Set a public variable,  $v, to 5.
   public $v = 5
}

class phpExtendClass1 extends phpClass1
{
# This class extends the class specified above.
   protected function __construct() {
   // This is ran when the class is constructed.
   // It is protected.

      // Set the value of $z to phpClass1's ($y value plus 2) multiplied by 3.
      // Note that the result would be the same without the parenthesis in this case.
      // Since $y = 0; in any other case where it didn't = 0, the parenthesis are neccessary.
      // To make sure the correct order is followed!
      final protected $z = ((phpClass1::__construct()) + 2) * 3 // Note that this would probably throw an error if $y was private.
      // Return a value for descendents.
      return $z
   }
}

class phpBase extends phpExtendClass1
{
# Like class phpExtendClass1 but extends it, and as the name implies, it will probably base other classes.
   private function __construct() {
   // This is ran when the class is constructed.
   // Only this class may access this function.

      // Set the value of $w to phpExtendClass1's ($z - phpClass1's ($y+5-(2*2)))
      final private $w = ((phpExtendClass1::__construct) - ((phpClass1::__construct)+5-(2*2))
      // Return $w for the next class function
      return $w
   }
   public function Base {
   // This is ran when called.
   // Anything can access this function.
      // Set $a to the value of $y
      public $a = (phpClass1::__construct)
      // Set $b to the value of $z
      public $b = (phpExtendClass1::__construct)
      // Set $c to the value of $w from initialize
      public $c = (phpBase::__construct)
      // Set $d to the value of the prototype class's $proto
      protected $d = (phpPrototype::__construct)
      // Return Nothing
      return NULL
   }
}
</script> <!-- This ends the PHP script. -->

<!-- If you wanted, you could put normal body text here; however, I won't be doing that. -->
</head> <!-- This terminates the head code. -->

<!-- Any plain text put here will be rendered in the body and may result in an error. -->

<body> <!-- This starts the body code. --><!-- Most people put actual things to display here. -->
<!-- Anything outside a tag will be rendered as plain text and thus, displayed as such. -->
<!-- However, it is unrecommended because that can lead to unusual problems and explicit definitions are more reliable and readable -->
<!-- Also, it is rendered as plain text and thus, cannot have a class or an id or a name. -->

<p class="html" id="para1">This is a sample text rendered as HTML.</p> <!-- This is a paragraph with the class "html" and id "para1". -->
<p class="js" id="para2">// This looks like a JS comment; however it is really just html.</p> <!-- This paragraph has class "js" and id "para2".-->

</body> <!-- This terminates the body code. -->

</html> <!-- This terminates the html code. -->


Yes, it is heavily commented, yes it is huge, yes, I'm submitting. So, what do you think; I'm a total noob at php and a beginner at JavaScript.


It'd be better to place this sort of code in something like Pastebin, as it's much easier to read code there, with the appropriate syntax highlighting and not having the code flood your post and loses the essence of your question.
Ircher
Yeah, okay, it is huge; I can't afford paste bin anyway. I heavily commented it because I wanted to show people the basics of HTML, PHP, JavaScript, CSS, and maybe MySQL! About the a is same as A, that was a typo; thanks for that about the html comments spanning more than one line however!
Marcuzzo
a noob?... subclassing?... seriously?
metalfreek
Using PHP classes and OOP and you call yourself Noob ....
Peterssidan
I must say I was surprised to see that PHP code inside a HTML script tag was parsed. It contains quite a lot of error though. You probably should have tested it before posting.
Related topics
De da vinci code
add some media code in the forum
PHP: Directory listing code
HCalculator - My Little Project
Problam about google ad code
One Liners for Code Cowboys
Show PHP Code
Warcraft III - Frozen Throne ( Cheat code )
Security Code Graphic
very simple PHP code to get search query string
Programming Help & Support Guidelines
What's wrong with this C code???
html and css code from form inputs
WinRAR Regreitry Code
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.