From 9f4cd60f36f05f777c65ee2ab790bdeb5aef943f Mon Sep 17 00:00:00 2001 From: Ajay-Dhangar Date: Sun, 26 Jan 2025 22:12:37 +0530 Subject: [PATCH 1/2] added colors folder content --- docs/PHP/_category.json | 8 - docs/PHP/home.md | 84 ---- docs/PHP/php-boolean.md | 101 ----- docs/PHP/php-comments.md | 105 ----- docs/PHP/php-constants.md | 113 ------ docs/PHP/php-data-types.md | 234 ------------ .../php-dollar-and-double-dollar-variables.md | 152 -------- docs/PHP/php-echo-print.md | 183 --------- docs/PHP/php-features.md | 67 ---- docs/PHP/php-hello-world.md | 78 ---- docs/PHP/php-history.md | 65 ---- docs/PHP/php-installation.md | 62 --- docs/PHP/php-integers.md | 89 ----- docs/PHP/php-introduction.md | 45 --- docs/PHP/php-magic-constants.md | 169 -------- docs/PHP/php-strings.md | 141 ------- docs/PHP/php-syntax.md | 103 ----- docs/PHP/php-type-casting.md | 360 ------------------ docs/PHP/php-type-juggling.md | 155 -------- docs/PHP/php-var-dump.md | 243 ------------ docs/PHP/php-variables.md | 168 -------- docs/css/colors/_category_.json | 8 + docs/css/colors/color-names.md | 200 ++++++++++ docs/css/colors/hex.md | 180 +++++++++ docs/css/colors/rgb.md | 131 +++++++ docs/css/colors/rgba.md | 119 ++++++ 26 files changed, 638 insertions(+), 2725 deletions(-) delete mode 100644 docs/PHP/_category.json delete mode 100644 docs/PHP/home.md delete mode 100644 docs/PHP/php-boolean.md delete mode 100644 docs/PHP/php-comments.md delete mode 100644 docs/PHP/php-constants.md delete mode 100644 docs/PHP/php-data-types.md delete mode 100644 docs/PHP/php-dollar-and-double-dollar-variables.md delete mode 100644 docs/PHP/php-echo-print.md delete mode 100644 docs/PHP/php-features.md delete mode 100644 docs/PHP/php-hello-world.md delete mode 100644 docs/PHP/php-history.md delete mode 100644 docs/PHP/php-installation.md delete mode 100644 docs/PHP/php-integers.md delete mode 100644 docs/PHP/php-introduction.md delete mode 100644 docs/PHP/php-magic-constants.md delete mode 100644 docs/PHP/php-strings.md delete mode 100644 docs/PHP/php-syntax.md delete mode 100644 docs/PHP/php-type-casting.md delete mode 100644 docs/PHP/php-type-juggling.md delete mode 100644 docs/PHP/php-var-dump.md delete mode 100644 docs/PHP/php-variables.md create mode 100644 docs/css/colors/_category_.json diff --git a/docs/PHP/_category.json b/docs/PHP/_category.json deleted file mode 100644 index 9c0f16fa5..000000000 --- a/docs/PHP/_category.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "label": "PHP", - "position": 20, - "link": { - "type": "generated-index", - "description": "PHP is a popular server-side scripting language known for its versatility and ease of use in web development. It is widely used for creating dynamic web pages, handling forms, interacting with databases, and building web applications. Key features of PHP include a large library of built-in functions, support for various databases like MySQL, PostgreSQL, and SQLite, integration with web servers like Apache and Nginx, and frameworks like Laravel, Symfony, and CodeIgniter. PHP is an essential tool for building dynamic and interactive websites." - } -} \ No newline at end of file diff --git a/docs/PHP/home.md b/docs/PHP/home.md deleted file mode 100644 index 0dbb47213..000000000 --- a/docs/PHP/home.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -id: php-tutorial -title: PHP - Home -sidebar_label: PHP - Home -sidebar_position: 1 -tags: [PHP, web development, server-side scripting, programming languages] -description: Learn about PHP, an open-source scripting language widely used for web development, server-side scripting, and building dynamic web applications. ---- - -# PHP Tutorial - -## What is PHP? - -PHP is an open-source general-purpose scripting language widely used for website development. It is developed by Rasmus Lerdorf. PHP stands for a recursive acronym PHP: Hypertext Preprocessor. - -PHP is the world’s most popular server-side programming language. Its latest version PHP 8.2.8 was released on July 4th, 2023. - -PHP is a server-side scripting language embedded in HTML. It is cross-platform, capable of running on all major operating systems and most web server programs such as Apache, IIS, lighttpd, and nginx. - -A large number of reusable classes and libraries are available on PEAR and Composer. PEAR (PHP Extension and Application Repository) is a distribution system for reusable PHP libraries or classes. Composer is a dependency management tool in PHP. - -### Why Learn PHP? - -PHP is one of the most preferred languages for creating interactive websites and web applications. PHP scripts can be easily embedded into HTML. With PHP, you can build: - -- Web Pages and Web-Based Applications -- Content Management Systems -- E-commerce Applications, etc. - -Several PHP-based web frameworks have been developed to speed up web application development. Examples include WordPress, Laravel, Symfony, etc. - -### Advantages of Using PHP - -PHP is a MUST for students and working professionals to become great Software Engineers, especially when they are working in the Web Development Domain. - -Some notable advantages of using PHP are: - -- Multi-paradigm language supporting imperative, functional, object-oriented, and procedural programming methodologies. -- Integrated with popular databases including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server. -- Zippy in execution, especially when compiled as an Apache module on the Unix side. -- Supports a number of protocols such as POP3, IMAP, and LDAP. -- Forgiving with a familiar C-like syntax. -- Practical nature characterized by Simplicity, Efficiency, Security, Flexibility, and Familiarity. - -### Hello World Using PHP - -```php - -``` - -### Audience - -This PHP tutorial is designed for programmers completely unaware of PHP concepts but with a basic understanding of computer programming. - -### Prerequisites - -Before proceeding with this tutorial, you need a basic understanding of computer programming. Knowledge of HTML, CSS, JavaScript, and databases is an added advantage. - -
- Frequently Asked Questions about PHP - - 1. Do I Need Prior Programming Experience to Learn PHP? - 2. Is PHP Free to Use? - 3. What are the Applications of PHP? - 4. How Do I Install PHP? - 5. What Tools and Technologies Work Well with PHP? - 6. Can PHP Be Used for Both Frontend and Backend Development? - 7. Are There Security Concerns with PHP? - 8. What Are the Latest Features and Updates in PHP? - 9. How Long Will it Take to Master PHP? - 10. What Resources Do I Need to Learn PHP? - -
- -```mermaid -graph LR -A[PHP] -- is --> B[Open-source] -A -- used for --> C[Website Development] -C -- embedded in --> D[HTML] -C -- runs on --> E[Major Operating Systems] -C -- integrates with --> F[Web Servers and Databases] -``` diff --git a/docs/PHP/php-boolean.md b/docs/PHP/php-boolean.md deleted file mode 100644 index 74827d796..000000000 --- a/docs/PHP/php-boolean.md +++ /dev/null @@ -1,101 +0,0 @@ ---- -id: php-boolean -title: PHP - Boolean -sidebar_label: PHP - Boolean -sidebar_position: 19 -tags: [PHP, boolean] ---- - -# PHP - Boolean - -In PHP, a boolean (bool) is a built-in scalar data type used to express truth values, which can be either True or False. Boolean literals use the constants True or False, which are case-insensitive. - -## Declaration and Usage - -You can declare a boolean variable as follows: - -```php -$a = true; -``` - -Logical operators like `<`, `>`, `==`, `!=`, etc., return boolean values. - -Example: - -```php -$gender = "Male"; -var_dump($gender == "Male"); -``` - -Output: - -``` -bool(true) -``` - -## Boolean Values in Control Statements - -Boolean values are integral to control statements such as if, while, for, and foreach. The behavior of these statements depends on the true/false value returned by boolean expressions. - -Example: - -```php -$mark = 60; - -if ($mark > 50) { - echo "pass"; -} else { - echo "fail"; -} -``` - -## Converting Values to Boolean - -Use the `(bool)` casting operator to convert values to boolean. In a logical context, values are automatically interpreted as boolean. - -- Non-zero numbers are considered true, except for 0 (+0.0 or -0.0) which is false. -- Non-empty strings are true, empty string "" is false. -- Non-empty arrays are true, empty array is false. - -Example: - -```php -$a = 10; -echo "$a: "; -var_dump((bool)$a); - -$a = 0; -echo "$a: "; -var_dump((bool)$a); - -$a = "Hello"; -echo "$a: "; -var_dump((bool)$a); - -$a = ""; -echo "$a: "; -var_dump((bool)$a); - -$a = array(); -echo "$a: "; -var_dump((bool)$a); -``` - -Output: - -``` -10: bool(true) -0: bool(false) -Hello: bool(true) -: bool(false) -Array: bool(false) -``` - -```mermaid -graph TD -A[Declaration] --> B[Logical Operations] -B --> C{Control Statements} -C --> D[Conversion to Boolean] -``` - -This diagram illustrates the flow of boolean handling in PHP, from declaration to usage in control statements and conversion of values to boolean. diff --git a/docs/PHP/php-comments.md b/docs/PHP/php-comments.md deleted file mode 100644 index d32832f94..000000000 --- a/docs/PHP/php-comments.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -id: php-comments -title: PHP - Comments -sidebar_label: PHP - Comments -sidebar_position: 8 -tags: [PHP, comments, web development] ---- - -# PHP - Comments - -## Introduction - -A comment in any computer program (such as a PHP program) is explanatory text that is ignored by the language compiler/interpreter. Its purpose is to help the user understand the logic used in the program algorithm. - -Although placing comments in the code is not essential, it is a highly recommended practice. The comments also serve as program documentation. Comments are also useful when the code needs to be debugged and modified. - -## Types of Comments in PHP - -There are two commenting formats in PHP: - -- Single-line Comments -- Multi-line Comments - -### Single-line Comments - -Single-line comments are generally used for short explanations or notes relevant to the local code. PHP uses two notations for inserting a single-line comment in a program. - -#### Single-line Comments Using "#" - -A line in PHP code starting with the "#" symbol is treated as a single-line comment. - -```php - -``` - -#### Single-line Comments Using "//" - -PHP also supports C style of single-line comments with the "//" symbol. A line starting with the double oblique symbol is treated as a comment. - -```php - -``` - -A comment that starts with the symbol "#" or "//" need not be closed. The effect of these symbols lasts till the end of the physical line. - -### Multi-line Comments - -Multi-line comments are generally used to provide pseudocode algorithms and more detailed explanations when necessary. - -The multiline style of commenting is the same as in C. One or more lines embedded inside the "/*" and "*/" symbols are treated as a comment. - -#### Example of Multi-line Comment in PHP - -Here is the example of a multi-line comment. - -```php - -``` - -Note that you can put even a single line inside the "/* .. */" symbols. However, if there is a "/*" symbol in the program, it must have a closing end-of-comment marker "*/". If not, an error will be displayed as follows: - -``` -PHP Parse error: Unterminated comment starting line 3 in /home/cg/root/65ded9eeb52fc/main.php on line 3 -``` - -## PHP Comments Diagram - -```mermaid -graph TD - A[Start] --> B[Single-line Comment] - B --> C[Using #] - B --> D[Using //] - A --> E[Multi-line Comment] - E --> F[/*...*/] -``` - -::: Note - -Placing comments in your code is a good practice. It helps in understanding and maintaining the code, especially when debugging or modifying it later. Comments serve as a form of documentation for your program, making it easier for others (or yourself) to understand the logic behind the code. - -::: - -## Table of PHP Comment Types - -| Comment Type | Symbol(s) | Example | -|---------------------|--------------|-----------------------------------| -| Single-line Comment | # | `# This is a single-line comment` | -| Single-line Comment | // | `// This is a single-line comment`| -| Multi-line Comment | /* ... */ | `/* This is a multi-line comment */`| diff --git a/docs/PHP/php-constants.md b/docs/PHP/php-constants.md deleted file mode 100644 index 179d2d767..000000000 --- a/docs/PHP/php-constants.md +++ /dev/null @@ -1,113 +0,0 @@ ---- -id: php-constants -title: PHP - Constants -sidebar_label: PHP - Constants -sidebar_position: 13 -tags: [PHP, constants] ---- - -# PHP - Constants - -## Introduction to Constants - -A constant in PHP is a name or identifier for a value that remains unchanged during the execution of the script. Constants are case-sensitive by default and are typically named using uppercase letters. - -### Valid and Invalid Constant Names - -- **Valid constant names**: - ```php - define("ONE", "first thing"); - define("TWO2", "second thing"); - define("THREE_3", "third thing"); - define("__THREE__", "third value"); - ``` -- **Invalid constant names**: - ```php - define("2TWO", "second thing"); - ``` - -## Difference between Constants and Variables - -- Constants are defined using `define()` and cannot be redefined or undefined. -- Constants have global scope and can be accessed anywhere in the script. - -## Defining a Named Constant - -The `define()` function is used to define constants in PHP. - -```php -define(string $const_name, mixed $value, bool $case = false): bool -``` - -- `$const_name`: The name of the constant. -- `$value`: The value of the constant (scalar or array). -- `$case`: Optional. If set to true, the constant will be case-insensitive. - -### Example - -```php - -``` - -## Using the `constant()` Function - -You can also use the `constant()` function to retrieve the value of a constant. - -```php -constant(string $name): mixed -``` - -### Example - -```php - -``` - -## Using the `defined()` Function - -The `defined()` function checks if a constant is defined. - -```php -defined(string $name): bool -``` - -### Example - -```php - -``` - -## Getting All Defined Constants - -PHP provides the `get_defined_constants()` function to retrieve all defined constants. - -### Example - -```php -"; - print_r($constants); - echo ""; -?> -``` - -This will display an associative array of all defined constants and their values. - -This concludes the overview of constants in PHP. \ No newline at end of file diff --git a/docs/PHP/php-data-types.md b/docs/PHP/php-data-types.md deleted file mode 100644 index 333c7ec48..000000000 --- a/docs/PHP/php-data-types.md +++ /dev/null @@ -1,234 +0,0 @@ ---- -id: php-data-types -title: PHP - Data Types -sidebar_label: PHP - Data Types -sidebar_position: 15 -tags: [PHP, data types] ---- -# PHP – Data Types - -The term "data types" refers to the classification of data into distinct categories. PHP has a total of eight data types that we use to construct our variables: - -1. **Integers**: Whole numbers, without a decimal point, like 4195. -2. **Doubles**: Floating-point numbers like 3.14159 or 49.1. -3. **Booleans**: Have only two possible values, either true or false. -4. **NULL**: Special type that only has one value: NULL. -5. **Strings**: Sequences of characters, like 'PHP supports string operations.' -6. **Arrays**: Named and indexed collections of other values. -7. **Objects**: Instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class. -8. **Resources**: Special variables that hold references to resources external to PHP (such as database connections). - -The first five are simple types, and the next two (arrays and objects) are compound types. The compound types can package up other arbitrary values of arbitrary type, whereas the simple types cannot. - -## Integer Data Type in PHP - -A whole number without a decimal point (like 4195) is of int type in PHP. Integer data types correspond to simple whole numbers, both positive and negative. They can be represented in decimal, hexadecimal, octal, or binary notation. - -To use octal notation, a number is preceded with "0o" or "0O". To use hexadecimal notation, precede the number with "0x". To use binary notation, precede the number with "0b". - -Here are some examples: - -| Notation | Examples | -|----------------------|-----------------------| -| Decimal Integer | 201, 4195, -15 | -| Octal Integer | 0010, 0O12, -0O21 | -| Hexadecimal Integer | 0x10, -0x100 | -| Binary Integer | 0b10101, -0b100 | - -Integers can be assigned to variables or used in expressions. - -## Double Data Type in PHP - -Double variables represent floating point numbers (also known as "floats", "doubles", or "real numbers") with a fractional component. They can be positive, negative, or zero. - -PHP also allows the use of scientific notation to represent floating-point numbers with more digits after the decimal point. The symbol "E" or "e" is used to separate the integer and fractional part. - -Here are some examples: - -| Notation | Examples | -|---------------------|-----------------------------| -| Decimal | 1.55, -123.0 | -| Scientific Notation | 1.2e3, 2.33e-4, 7E-10, 1.0E5| - -By default, doubles print with the minimum number of decimal places needed. - -## Boolean Data Type in PHP - -The bool type in PHP has only two values: true or false. It is used to express a truth value. - -You can also use the integer values "1" and "0" to represent True and False Boolean values. - -Here are some examples: - -```php -$bool1 = true; -$bool2 = false; -$bool3 = 1; -$bool4 = 0; -``` - -Interpreting other data types as Booleans follows certain rules: - -- If the value is a number, it is False only if the value is equal to zero, otherwise, the value is True. -- If the value is a string, it is False if the string is empty or is the string "0", and is True otherwise. -- Values of type NULL are always False. -- If the value is an array, it is False if it contains no other values; True otherwise. - -Do not use double as Booleans. - -## String Data Type in PHP - -A string in PHP is a sequence of characters. PHP supports both single-quoted and double-quoted string formation. Double-quoted strings replace variables with their values and interpret certain character sequences. - -Here are some examples: - -```php -$string1 = "This is a string in double quotes"; -$string2 = 'This is a somewhat longer, singly quoted string'; -``` - -PHP also supports Heredoc and Nowdoc representations of string data type. - -### Heredoc Representation - -You can assign multiple lines to a single string variable using heredoc. - -```php -$channel =<<<_XML_ - - - What's For Dinner - http://menu.example.com/ - Choose what to eat tonight. - -_XML_; - -echo <<< END - This uses the "here document" syntax to output multiple lines with - variable interpolation. Note that the here document terminator must - appear on a line with just a semicolon. no extra whitespace! -END; - -print $channel; -``` - -### Nowdoc Representation - -All the rules for heredoc identifiers also apply to nowdoc identifiers. A nowdoc is specified just like a heredoc, but there is no parsing inside a nowdoc. You can use the nowdoc construct for embedding large blocks of text without having to use any escape characters. - -```php -echo <<<'IDENTIFIER' - As the cat cleared its throat with a refined "Meow", - the squirrel chirped excitedly about its latest - discovery of a hidden stash of peanut treasure! -IDENTIFIER; -``` - -## Null Data Type in PHP - -In PHP, null represents a special type that only has one value: NULL. Undefined and unset() variables will resolve to the value "null". Programmers use the Null data type in PHP to initialize variables or to indicate that a value is missing. - -To give a variable the NULL value, simply assign it like this − - -```php -$my_var = NULL; -``` - -The special constant NULL is capitalized by convention, but actually, it is case insensitive; you could just as well have typed − - -```php -$my_var = null; -``` - -## Array Data Type in PHP - -An array in PHP is an ordered map, where a key is associated with one or more values. PHP arrays can be defined using the array() function or with square brackets. - -Here are some examples: - -```php -$arr1 = array("foo" => "bar", "bar" => "foo"); -$arr2 = ["foo" => "bar", "bar" => "foo"]; -$arr3 = ["foo", "bar", "hello", "world"]; -``` - -In a multi-dimensional array, each element in the main array can also be an array. Values in the multi-dimensional array are accessed using multiple indexes. - -## Object Data Type in PHP - -An object type is an instance of a programmer-defined class, which can package up both other kinds of values and functions that are specific to the class. - -To create a new object, use the new statement to instantiate a class. - -```php -class Foo { - function bar() { - echo "Hello World."; - } -} -$obj = new Foo; -$obj->bar(); -``` - -## Resource Data Type in PHP - -Resources are special variables that hold references to resources external to PHP (such as a file stream or database connections). - -Here is an example of file resource − - -```php -$fp = fopen("foo.txt", "w"); -``` - -## Example: The gettype() Function - -The gettype() function is helpful to find out the type of data stored in a variable. - -```php -$x = 10; -echo gettype($x) . "\n"; - -$y = 10.55; -echo gettype($y) . "\n"; - -$z = [1,2,3,4,5]; -echo gettype($z); -``` - -``` -Output: -integer -double -array -``` - -The data types of variables in PHP are determined at runtime based on the values that are assigned to them. - -```mermaid -flowchart TD - start[Start] --> define[Define Data Types] - define --> integer - define --> double - define --> boolean - define --> string - define --> null - define --> array - define --> object - define --> resource - integer --> operations[Integer Operations] - double --> operations2[Double Operations] - boolean --> operations3[Boolean Operations] - string --> operations4[String Operations] - array --> operations5[Array Operations] - object --> operations6[Object Operations] - resource --> operations7[Resource Operations] - operations --> endNode[End] - operations2 --> endNode - operations3 --> endNode - operations4 --> endNode - operations5 --> endNode - operations6 --> endNode - operations7 --> endNode -``` - -This mermaid diagram outlines the flow of data types in PHP and their respective operations. diff --git a/docs/PHP/php-dollar-and-double-dollar-variables.md b/docs/PHP/php-dollar-and-double-dollar-variables.md deleted file mode 100644 index 701dd5dc4..000000000 --- a/docs/PHP/php-dollar-and-double-dollar-variables.md +++ /dev/null @@ -1,152 +0,0 @@ ---- -id: php-dollar-and-double-dollar-variables -title: PHP - $ and $$ Variables -sidebar_label: PHP - $ and $$ Variables -sidebar_position: 12 -tags: [PHP, variables, dynamic variables] ---- -# PHP - $ and $$ Variables - -## Introduction -PHP uses the convention of prefixing the variable names by the `$` symbol. PHP also has the provision of declaring dynamic variables by prefixing two dollar symbols `$$` to the name. A variable variable (or a dynamic variable) can be set and used dynamically. - -## Syntax -The declaration of a normal variable is like this − - -```php -$a = 'good'; -``` - -A dynamic variable takes the value of a normal variable and treats that as the name of the variable. In the above example, "good" can be used as the name of a variable by using two dollar signs `$$` − - -```php -$$a = 'morning'; -``` - -We now have two variables: `$a` with contents `good` and `$$a` with contents `morning`. As a result, the following echo statements will produce the same output − - -```php -echo "$a {$$a}"; -echo "$a $good"; -``` - -Both produce the same output − - -``` -good morning -``` - -## Example 1 -Take a look at this following example − - -```php - -``` - -It will produce the following output − - -``` -good morning -good morning -``` - -## Example 2 -Let's take a look at another example − - -```php - -``` - -Here, you will get the following output − - -``` -Value of x = foo -Value of $$x = bar -Value of foo = bar -``` - -## Using Multiple `$` Symbols -Note that the use of `$` symbol is not restricted to two. Any number of dollar symbols can be prefixed. - -Suppose there is a variable `$x` with `a` as its value. Next, we define `$$x='as'`, then `$$x` as well as `$a` will have the same value. Similarly, the statement `$$$x='and'` effectively declares a `$as` variable whose value is 'and'. - -### Example -Here is a complete example that shows the use of multiple `$` symbols. - -```php - -``` - -When you run this code, it will produce the following output − - -``` -$a= Hello -$$a= World -$$$a= lang -$$$$a= php -$$$$$a= a -``` - -## Using Dynamic Variables with Arrays -Using dynamic variables with arrays may lead to certain ambiguous situations. With an array `a`, if you write `$$a[1]`, then the parser needs to know if you are referring to `$a[1]` as a variable or if you want `$$a` as the variable and then the `[1]` index from that variable. - -To resolve this ambiguity, use `${$a[1]}` for the first case and `${$a}[1]` for the second. - -### Example -Take a look at the following example − - -```php - -``` - -It will produce the following output − - -``` -Intel -Linux -PHP -Intel -Linux -PHP -``` - -:::note - This technique cannot be used with PHP's Superglobal arrays within functions or class methods. The variable `$this` is a special variable in PHP and it cannot be referenced dynamically. -::: \ No newline at end of file diff --git a/docs/PHP/php-echo-print.md b/docs/PHP/php-echo-print.md deleted file mode 100644 index 8ca23bc83..000000000 --- a/docs/PHP/php-echo-print.md +++ /dev/null @@ -1,183 +0,0 @@ ---- -id: php-echo-print -title: PHP - Echo/Print -sidebar_label: PHP - Echo/Print -sidebar_position: 10 -tags: [PHP, echo, print, output] ---- - -# PHP - Echo/Print - -## Introduction - -In PHP, both `echo` and `print` statements are used to render the output either on the browser or the PHP console. Both of them are not functions but language constructs. Hence, parentheses should not be used with either of them. - -## The "echo" Statement in PHP - -The `echo` statement is used with the following syntax: - -```php -echo(string ...$expressions): void -``` - -The `echo` statement outputs one or more expressions, with no additional newlines or spaces. - -### Example - -Here is an example of how the `echo` statement works in PHP: - -```php - -``` - -It will produce the following output: - -``` -Hello Rajesh How are you? -``` - -Since a double-quoted string is similar to a single-quoted string in PHP, the following statement produces the same output: - -```php -echo 'Hello ' . $name . ' How are you?'; -``` - -### Example - -A double-quoted string outputs the value of the variable. Hence, the following statement inserts the value of `$name` variable before printing the output. - -```php - -``` - -It will produce the following output: - -``` -Hello Rajesh How are you? -``` - -### Example - -But, a single-quoted string will output `$name` as it is. - -```php - -``` - -It will produce the following output: - -``` -Hello $name How are you? -``` - -A string passed to an `echo` statement can either be passed individually as multiple arguments or concatenated together and passed as a single argument. So, both the following statements are valid: - -```php -echo 'Hello ', 'how ', 'are ', 'you?', "\n"; -echo 'Hello ' . 'how ' . 'are ' . 'you?' . "\n"; -``` - -### Example - -Note that the output of the two successive `echo` statements will be rendered in the same line if the newline character is not used. Take a look at the following example: - -```php - -``` - -It will produce the following output: - -``` -helloworld -``` - -## The "print" Statement in PHP - -The `print` statement is similar to `echo`, but it outputs an expression. - -```php -print(string $expression): int -``` - -Like `echo`, `print` is also a language construct. Its argument is an expression but it is not put in parentheses. - -The major difference is that the `print` statement in PHP accepts a single argument only and always returns 1. - -### Example - -Take a look at this following example: - -```php - -``` - -It will produce the following output: - -``` -Hello Rajesh How are you? -Hello Rajesh How are you? -``` - -## Output Multiline Strings Using Print/Echo - -Both `echo` and `print` statements can output multiline strings spanning over more than one line in the editor. Take a look at the following example: - -```php - -``` - -It will produce the following output: - -``` -Multi-line -string can be output -by echo as well as -print statement in PHP -``` - -The output will remain the same if we replace `print` with `echo`. - -## PHP Echo/Print Diagram - -```mermaid -graph TD - A[Start] --> B[echo Statement] - B --> C[Outputs one or more expressions] - B --> D[No additional newlines or spaces] - A --> E[print Statement] - E --> F[Outputs an expression] - E --> G[Returns 1] - A --> H[Multiline Strings] - H --> I[echo can output multiline strings] - H --> J[print can output multiline strings] -``` - -:::note - -Understanding the differences and similarities between `echo` and `print` helps in effectively rendering output in PHP. Both constructs are essential for displaying information in PHP scripts. - -::: \ No newline at end of file diff --git a/docs/PHP/php-features.md b/docs/PHP/php-features.md deleted file mode 100644 index 997aaad84..000000000 --- a/docs/PHP/php-features.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -id: php-features -title: PHP - Features -sidebar_label: PHP - Features -sidebar_position: 5 -tags: [PHP, features, programming languages, server-side scripting] ---- - -# PHP - Features - -PHP (Hypertext Preprocessor) is an open-source server-side scripting language primarily used for web development. Let's explore some of its key features: - -## PHP Features - -### Simple and Easy to Learn - -PHP has a syntax that's simpler compared to languages like C, Java, and Perl. This makes it easier for developers, especially those familiar with other languages, to understand and work with. It offers a wide range of pre-defined functions, enabling rapid web application development. - -### Open Source - -PHP is free and open-source, encouraging a large and active developer community. This community contributes to its development, offers support through forums and tutorials, and shares valuable resources like documentation. - -### Cross-Platform Compatible - -PHP is compatible with various operating systems (Windows, Linux, macOS, UNIX) and databases (MySQL, PostgreSQL, MongoDB). This cross-platform compatibility allows PHP-based applications to run seamlessly across different environments without modifications. - -### Server-Side Scripting - -PHP excels in server-side scripting, processing scripts on the web server and delivering HTML to the client's web browser. This facilitates dynamic webpage creation, session management, form handling, and database interactions essential for online applications. - -### Database Integration - -PHP offers robust support for database interaction, including built-in functions for database connectivity and a database abstraction layer for seamless application-database communication. This makes it easy to develop database-driven web applications. - -### Extensive Library Support - -PHP provides extensive libraries for various functionalities such as image processing, encryption, PDF generation, XML/JSON parsing, session management, and more. These libraries streamline development and enhance application capabilities. - -### Security Features - -PHP incorporates security features like data encryption functions (e.g., Sha1, MD5), input validation functions (e.g., filter_var), and secure communication protocols (HTTPS). Third-party security applications further enhance PHP's security capabilities. - -### Memory and Session Management - -PHP ensures efficient memory management and session handling, optimizing performance and resource utilization. Its code runs in its memory space, leading to faster execution compared to other scripting languages. - -### Active Community and Support - -With a vibrant developer community, PHP receives continuous updates, support, and contributions. Developers can easily seek help, share knowledge, and collaborate on projects, ensuring PHP remains modern, secure, and well-supported. - -:::note -Explore the [PHP Manual](https://www.php.net/manual/en/) for detailed documentation and guides on PHP features. -::: - -## PHP Features Diagram - -```mermaid -graph TD - A(Simple and Easy to Learn) --> B(Open Source) - B --> C(Cross-Platform Compatible) - C --> D(Server-Side Scripting) - D --> E(Database Integration) - E --> F(Extensive Library Support) - F --> G(Security Features) - G --> H(Memory and Session Management) - H --> I(Active Community and Support) -``` \ No newline at end of file diff --git a/docs/PHP/php-hello-world.md b/docs/PHP/php-hello-world.md deleted file mode 100644 index ff980dd8a..000000000 --- a/docs/PHP/php-hello-world.md +++ /dev/null @@ -1,78 +0,0 @@ ---- -id: php-hello-world -title: PHP - Hello World -sidebar_label: PHP - Hello World -sidebar_position: 7 -tags: [PHP, hello world, web development, XAMPP] ---- - -# PHP - Hello World - -## Introduction - -The "Hello World" program is a common starting point for beginners learning a new programming language. Let's dive into creating a simple "Hello World" program in PHP using XAMPP. - -## Prerequisites - -Ensure that you have XAMPP installed, which includes the Apache server and PHP module. - -## Writing and Running the Program - -1. Open your preferred text editor. -2. Save the following code as `hello.php` in the `htdocs` directory of your XAMPP installation. - -```php - -``` - -3. Start the Apache server from the XAMPP control panel if it's not already running. -4. Open a new tab in your browser and enter `http://localhost/hello.php` as the URL. -5. You should see the "Hello World" message displayed in the browser window. - -## Mixing HTML with PHP - -You can mix HTML and PHP code in a single script. For example: - -```php - - - -

My PHP Website

- - - -``` - -The "Hello World" message will be rendered as plain text, but you can include HTML tags inside the PHP code for formatting. - -## Running PHP Scripts from Command Prompt - -You can also run PHP scripts from the command prompt. Assuming you have a `hello.php` file with the following content: - -```php - -``` - -1. Add the path of the PHP executable (e.g., `php.exe` in XAMPP) to your operating system’s path environment variable. -2. Open a command prompt and navigate to the directory containing `hello.php`. -3. Run the script using the command: - -```bash -php hello.php -``` - -You will see the output: - -``` -Hello PHP!!!!! -``` - -:::note -Ensure that XAMPP is properly configured and the Apache server is running to execute PHP scripts. -::: diff --git a/docs/PHP/php-history.md b/docs/PHP/php-history.md deleted file mode 100644 index dd5f20668..000000000 --- a/docs/PHP/php-history.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -id: php-history -title: PHP - History -sidebar_label: PHP - History -sidebar_position: 4 -tags: [PHP, history, programming languages, versions] ---- - -# PHP - History - -PHP started as a small open-source project that gradually evolved as more people discovered its usefulness. Here's a brief overview of its history and major milestones: - -## Early Days - -Rasmus Lerdorf released the first version of PHP in 1994. Originally, PHP stood for "Personal Home Page" as it was used to maintain his personal homepage. Over time, database support was added, and it became known as "Personal Home Page/Forms Interpreter" or PHP/FI, capable of building dynamic web applications. - -## PHP 3 and Beyond - -In 1997, Zeev Suraski and Andi Gutmans rewrote the parser, laying the foundation for PHP 3. The language was renamed to PHP: Hypertext Preprocessor, reflecting its recursive nature. The Zend Engine, a compiler and runtime environment for PHP, powered PHP 4 released in May 2000. - -## PHP 5 - -PHP 5, released in 2004, introduced significant features like Object-Oriented Programming (OOP) support, PHP Data Objects (PDO), and performance enhancements. - -## PHP 7 - -PHP 7, developed in 2015, brought new language features including return type declarations and scalar types in parameter and return type declarations. - -## PHP 8 - -PHP 8, the latest major version released in November 2020, introduced notable features such as Just-in-time (JIT) Compilation, the "match" expression, union types, mixed type, static return type, and attributes for adding metadata to PHP classes. - -:::note -Explore the [PHP Manual](https://www.php.net/manual/en/) for detailed documentation and guides on PHP versions and features. -::: - -## Major Version Timeline - -Here's a summary of important milestones in PHP's release history: - -| Version | Description | -| ------- | ----------- | -| 1.0 | (8 June 1995) Officially called "Personal Home Page Tools (PHP Tools)". | -| 2.0 | (1 November 1997) Officially called "PHP/FI 2.0". | -| 3.0 | (6 June 1998) Development expanded to multiple developers. | -| 4.0 | (22 May 2000) Introduced Zend Engine. | -| 5.0 | (13 July 2004) Zend Engine II with new features. | -| 5.1 | (24 November 2005) Performance improvements and PDO introduction. | -| 6.x | Not released. Abandoned version with native Unicode support plan. | -| 7.0 | (3 December 2015) Zend Engine 3, new syntax, and features. | -| 7.3 | (6 December 2018) Flexible Heredoc/Nowdoc syntax. | -| 8.0 | (26 November 2020) JIT compilation, new operators, and types. | - -```mermaid -graph LR - A[PHP 1.0] --> B[PHP 2.0] - B --> C[PHP 3.0] - C --> D[PHP 4.0] - D --> E[PHP 5.0] - E --> F[PHP 5.1] - F --> G[PHP 6.x] - G --> H[PHP 7.0] - H --> I[PHP 7.3] - I --> J[PHP 8.0] -``` \ No newline at end of file diff --git a/docs/PHP/php-installation.md b/docs/PHP/php-installation.md deleted file mode 100644 index dffa853ea..000000000 --- a/docs/PHP/php-installation.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -id: php-installation -title: PHP - Installation -sidebar_label: PHP - Installation -sidebar_position: 3 -tags: [PHP, web development, server-side scripting, programming languages, XAMPP] ---- - -# PHP - Installation - -You can start learning the basics of programming in PHP with the help of any of the online PHP compilers freely available on the Internet. This will help in getting acquainted with the features of PHP without installing it on your computer. Later on, install a full-fledged PHP environment on your local machine. - -One such online PHP compiler is provided by Tutorialpoint’s "Coding Ground for Developers". Visit [Tutorialspoint Coding Ground](https://www.tutorialspoint.com/codingground.htm), enter PHP script and execute it. - -## PHP Installation - -However, to be able to learn the advanced features of PHP, particularly related to the web concepts such as server variables, using backend databases, etc., you need to install the PHP environment on your local machine. - -In order to develop and run PHP Web pages, you need to install three vital components on your computer system: - -1. **Web Server:** PHP will work with virtually all Web Server software, including Apache, NGINX, or Lighttpd. The most often used web server software is the freely available Apache Server. [Download Apache](https://httpd.apache.org/download.cgi) - -2. **Database:** PHP will work with virtually all database software, including MySQL, Oracle, and Sybase. The most commonly used is the freely available MySQL database. [Download MySQL](https://www.mysql.com/downloads/) - -3. **PHP Parser:** In order to process PHP script instructions, a parser must be installed to generate HTML output that can be sent to the Web Browser. - -Although it is possible to install these three components separately and configure the installation correctly, it is a little complex process, particularly for beginners. Instead, using any all-in-one packaged distribution that contains precompiled Apache, MySQL, and PHP binaries is convenient. - -## XAMPP Installation - -One popular all-in-one solution is XAMPP, from Apache Friends. It includes Apache, MariaDB (a fork of MySQL), PHP, and Perl. XAMPP is cross-platform, available for Windows, Linux, and OS X. - -To download XAMPP, visit the [Apache Friends website](https://www.apachefriends.org/download.html) and download the installer for your operating system. - -### Windows Installation - -1. Download the installer from [SourceForge](https://sourceforge.net/projects/xampp/). -2. Run the installer and follow the wizard-based installation. -3. Provide administrator access and choose the installation directory (default is "c:\xampp"). - -### Linux Installation - -1. Change the permissions to the installer: - - ```bash - chmod 755 xampp-linux-*-installer.run - ``` - -2. Run the installer: - - ```bash - sudo ./xampp-linux-*-installer.run - ``` - -3. XAMPP is installed in "/opt/lamp" directory. - -### OS X Installation - -1. Open the DMG image and double-click the image to start the installation process. -2. Start XAMPP using the XAMPP Control Panel. - -For detailed instructions on managing servers and PHP with XAMPP, refer to the XAMPP documentation. diff --git a/docs/PHP/php-integers.md b/docs/PHP/php-integers.md deleted file mode 100644 index e0917469a..000000000 --- a/docs/PHP/php-integers.md +++ /dev/null @@ -1,89 +0,0 @@ ---- -id: php-integers -title: PHP - Integers -sidebar_label: PHP - Integers -sidebar_position: 20 -tags: [PHP, integers] ---- - -# PHP - Integers - -In PHP, an integer (int) is a built-in scalar data type representing whole numbers without decimal points. Integers can be represented in decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation. - -## Integer Notation Examples - -Example: - -```php -$a = 1234; -echo "1234 is an Integer in decimal notation: $a\n"; - -$b = 0123; -echo "0o123 is an integer in Octal notation: $b\n"; - -$c = 0x1A; -echo "0xaA is an integer in Hexadecimal notation: $c\n"; - -$d = 0b1111; -echo "0b1111 is an integer in binary notation: $d"; -``` - -Output: - -``` -1234 is an Integer in decimal notation: 1234 -0o123 is an integer in Octal notation: 83 -0xaA is an integer in Hexadecimal notation: 26 -0b1111 is an integer in binary notation: 15 -``` - -## Underscore Separator in Integer Literals - -From PHP 7.4.0 onwards, integer literals may contain underscores (_) as separators between digits for better readability. - -Example: - -```php -$a = 1_234_567; -echo "1_234_567 is an Integer with _ as separator: $a"; -``` - -Output: - -``` -1_234_567 is an Integer with _ as separator: 1234567 -``` - -## Integer Size and Range - -PHP does not support unsigned integers. The size of an int is platform-dependent. On 32-bit systems, the maximum value is about two billion. 64-bit platforms usually have a maximum value of about 9E18. - -Constants like PHP_INT_SIZE, PHP_INT_MAX, and PHP_INT_MIN provide information about integer size, maximum, and minimum values. - -## Integer Division - -PHP doesn't have a specific operator for integer division. Division between an integer and a float always results in a float. To obtain integral division, use `intval()` or `intdiv()`. - -Example: - -```php -$x = 10; -$y = 3.5; -$z = $x / $y; -var_dump($z); // float(2.857142857142857) - -$z = intdiv($x, $y); -var_dump($z); // int(3) -``` - -## Mermaid Diagram - -```mermaid -graph TD -A[Integers] --> B[Notation Examples] -B --> C[Underscore Separator] -C --> D[Integer Size and Range] -D --> E[Integer Division] -``` - -This diagram illustrates different aspects of integers in PHP, including notation examples, underscore separator usage, size and range, and integer division. diff --git a/docs/PHP/php-introduction.md b/docs/PHP/php-introduction.md deleted file mode 100644 index b7688e969..000000000 --- a/docs/PHP/php-introduction.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -id: php-introduction -title: PHP - Introduction -sidebar_label: PHP - Introduction -sidebar_position: 2 -tags: [PHP, web development, server-side scripting, programming languages] ---- - -# PHP - Introduction - -PHP started out as a small open-source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf released the first version of PHP way back in 1994. Initially, PHP was supposed to be an abbreviation for "Personal Home Page", but it now stands for the recursive initialism "PHP: Hypertext Preprocessor". - -Lerdorf began PHP development in 1993 by writing several Common Gateway Interface (CGI) programs in C, which he used to maintain in his personal homepage. Later on, He extended them to work with web forms and to communicate with databases. This implementation of PHP was "Personal Home Page/Forms Interpreter" or PHP/FI. - -Today, PHP is the world’s most popular server-side programming language for building web applications. Over the years, it has gone through successive revisions and versions. - -## PHP Versions - -- **PHP 1.0:** Developed by Rasmus Lerdorf in 1994 as a simple set of CGI binaries written in C. -- **PHP 2.0 (PHP/FI):** Introduced in April 1996, included built-in support for DBM, mSQL, and Postgres95 databases, cookies, user-defined function support. -- **PHP 3.0:** Developed by Zeev Suraski and Andi Gutmans, provided a mature interface for multiple databases, protocols, APIs, object-oriented programming support, and consistent language syntax. -- **PHP 4.0:** Released in May 2000 powered by Zend Engine, had support for many web servers, HTTP sessions, output buffering, secure ways of handling user input, and several new language constructs. -- **PHP 5.0:** Released in July 2004, driven by Zend Engine 2.0 with a new object model and other new features. -- **PHP 7.0:** Released in Dec 2015 with improved performance, reduced memory usage, Return and Scalar Type Declarations, and Anonymous Classes. -- **PHP 8.0:** Released on 26 November 2020 with substantial improvements including Just-in-time compilation (JIT). - -## PHP Application Areas - -PHP is one of the most widely used languages over the web. Here are some of its application areas: - -- Server-side scripting embedded in HTML. -- Managing dynamic content, databases, session tracking, building e-commerce sites. -- Outputting rich file types (images, PDF files), encrypting data, sending emails. -- Running on all major operating system platforms and web server programs. -- Handling system functions, forms, cookies, database operations, access control, encryption, and more. -- Providing a large number of reusable classes and libraries available on "PEAR" and "Composer". - -```mermaid -graph LR -A[PHP] -- is --> B[Open-source] -A -- used for --> C[Website Development] -C -- embedded in --> D[HTML] -C -- runs on --> E[Major Operating Systems] -C -- integrates with --> F[Web Servers and Databases] -``` diff --git a/docs/PHP/php-magic-constants.md b/docs/PHP/php-magic-constants.md deleted file mode 100644 index b49b6502f..000000000 --- a/docs/PHP/php-magic-constants.md +++ /dev/null @@ -1,169 +0,0 @@ ---- -id: php-magic-constants -title: PHP - Magic Constants -sidebar_label: PHP - Magic Constants -sidebar_position: 14 -tags: [PHP, magic constants] ---- - -# PHP - Magic Constants - -## Introduction to Magic Constants - -Magic constants in PHP are predefined constants that change based on their usage and are resolved at compile time. They are case insensitive and provide information about the current context of the script. - -### List of Magic Constants - -1. `__LINE__`: Returns the current line number in the file. -2. `__FILE__`: Returns the full path and filename of the file. -3. `__DIR__`: Returns the directory of the file. -4. `__FUNCTION__`: Returns the function name. -5. `__CLASS__`: Returns the class name. -6. `__METHOD__`: Returns the method name. -7. `__TRAIT__`: Returns the trait name. -8. `__NAMESPACE__`: Returns the current namespace name. - -## Examples of Magic Constants - -### `__LINE__` - -```php - -``` -Output: -``` -Hello World. The current Line number is 5. -``` - -### `__FILE__` - -```php - -``` -Output: -``` -Hello World. Current PHP script name is C:\xampp\htdocs\hello.php. -``` - -### `__DIR__` - -```php - -``` -Output: -``` -Hello World. Directory of the Current PHP script name is C:\xampp\htdocs. -``` - -### `__FUNCTION__` - -```php - -``` -Output: -``` -Hello World. The function name is hello. -``` - -### `__CLASS__` - -```php -getClassName(); -?> -``` -Output: -``` -Inside the constructor of MyClass -from an instance method of MyClass -``` - -### `__METHOD__` - -```php -"; - } - function myMethod(){ - echo "Calling " . __METHOD__ . " of " . __CLASS__ .""; - } - } - $obj = new MyClass; - $obj->myMethod(); -?> -``` -Output: -``` -Calling MyClass::__construct of MyClass -Calling MyClass::myMethod of MyClass -``` - -### `__TRAIT__` - -```php -hello(); -?> -``` -Output: -``` -Hello World from MyTrait -``` - -### `__NAMESPACE__` - -```php - -``` -Output: -``` -Name of the class: MyNamespace\MyClass in MyNamespace -``` - -## Conclusion - -These magic constants provide valuable information about the context in which they are used, enhancing the flexibility and functionality of PHP scripts. diff --git a/docs/PHP/php-strings.md b/docs/PHP/php-strings.md deleted file mode 100644 index f09584c96..000000000 --- a/docs/PHP/php-strings.md +++ /dev/null @@ -1,141 +0,0 @@ ---- -id: php-strings -title: PHP - Strings -sidebar_label: PHP - Strings -sidebar_position: 18 -tags: [PHP, strings] ---- - -# PHP - Strings - -A string in PHP is a sequence of characters, represented as either single-quoted or double-quoted strings. PHP treats strings as arrays of bytes, where each character is a byte. It's important to note that PHP does not offer native Unicode support and supports a 256-character set. - -## Single-Quoted Strings - -A single-quoted string is a sequence of characters enclosed in single quotes ('). - -Example: - -```php -$str = 'this is a simple string'; -``` - -To include a literal single quote in a single-quoted string, escape it with a backslash (\). - -Example: - -```php -$str = 'This is a \'simple\' string'; -echo $str; -``` - -Output: - -``` -This is a 'simple' string -``` - -## Double-Quoted Strings - -A double-quoted string is a sequence of characters enclosed in double quotes ("). - -Example: - -```php -$str = "this is a simple string"; -``` - -Double-quoted strings interpret certain escape sequences like "\r" and "\n" for special characters. - -### Escape Sequences in Double-Quoted Strings - -| Sequence | Meaning | -|----------|--------------------------| -| \n | linefeed (LF) | -| \r | carriage return (CR) | -| \t | horizontal tab (HT) | -| \v | vertical tab (VT) | -| \e | escape (ESC) | -| \f | form feed (FF) | -| \\ | backslash | -| \$ | dollar sign | -| \" | double-quote | - -Example: - -```php -$str = "Hello\nWorld!"; -echo $str; -``` - -Output: - -``` -Hello -World! -``` - -## Octal and Hexadecimal Escapes - -PHP supports escaping octal and hexadecimal characters to their ASCII equivalents using "\nnn" and "\xhh" respectively. - -Example: - -```php -$str = "\120\110\120"; -echo "PHP with Octal: ". $str; - -$str = "\x50\x48\x50"; -echo "PHP with Hexadecimal: ". $str; -``` - -Output: - -``` -PHP with Octal: PHP -PHP with Hexadecimal: PHP -``` - -## String Concatenation and Special Characters - -To concatenate strings in PHP, use the dot (.) operator. - -Example: - -```php -$string1 = "Hello World"; -$string2 = "1234"; - -echo $string1 . " " . $string2; -``` - -Output: - -``` -Hello World 1234 -``` - -## String Functions - -PHP provides various string functions for string manipulation: - -- `strlen()`: Returns the length of a string. -- `strpos()`: Searches for a string or character within a string. - -For example: - -```php -echo strlen("Hello world!"); // Outputs: 12 -echo strpos("Hello world!", "world"); // Outputs: 6 -``` - -```mermaid -graph TD -A[Single-Quoted String] -->|Escape Single Quote| B{Single-Quoted String} -B -->|Literal Single Quote| C(string with escaped quote) -A -->|Double-Quoted String| D{Double-Quoted String} -D -->|Escape Sequences| E{Interpreted Escape Sequences} -E -->|Special Characters| F[Output with special characters] -A -->|Octal and Hexadecimal Escapes| G{Octal and Hexadecimal Escapes} -G -->|ASCII Equivalents| H[Output with ASCII equivalents] -``` diff --git a/docs/PHP/php-syntax.md b/docs/PHP/php-syntax.md deleted file mode 100644 index e06ac04ea..000000000 --- a/docs/PHP/php-syntax.md +++ /dev/null @@ -1,103 +0,0 @@ ---- -id: php-syntax -title: PHP - Syntax -sidebar_label: PHP - Syntax -sidebar_position: 6 -tags: [PHP, syntax, programming languages, server-side scripting] ---- - -# PHP - Syntax - -The syntax rules of PHP are similar to the C language. PHP is primarily a server-side scripting language used for web development. Let's dive into the details of PHP syntax. - -## PHP Syntax Overview - -### File Structure and Execution - -A PHP code is typically stored in a text file with a ".php" extension. When opened in a browser with an HTTP protocol URL, the PHP code is executed by the server. PHP files may contain HTML, CSS, JavaScript, and PHP code blocks. - -### PHP Tags - -#### Canonical PHP Tags - -The most universally effective PHP tag style is: - -```php - -``` - -Using this style ensures correct interpretation of PHP tags. - -#### Short-open (SGML-style) Tags - -Short tags look like this: - -```php - -``` - -To enable short tags, you must either configure PHP with "--enable-short-tags" or set "short_open_tag=on" in php.ini. - -#### Escaping from HTML - -PHP code can be embedded within HTML documents using PHP tags. For example: - -```php -

This is a HTML statement

- -

This is another HTML statement.

-``` - -PHP skips blocks outside PHP tags based on conditions, enhancing code readability and efficiency. - -### Basic Syntax - -#### Statements - -PHP statements are expressions terminated by semicolons (;). For example: - -```php -$greeting = "Welcome to PHP!"; -``` - -#### Expressions - -Expressions in PHP are combinations of tokens like numbers, strings, variables, constants, and keywords such as "if", "else", "while", "for", etc. - -#### Blocks - -Blocks of statements are enclosed in curly braces ({}) to create logical structures. For example: - -```php -if (3 == 2 + 1) { - echo "Good - I haven't totally"; - echo "lost my mind."; -} -``` - -### Case Sensitivity - -PHP is case sensitive, meaning variable names, function names, and other identifiers must match case exactly. - -:::note -PHP syntax is crucial for building dynamic and interactive web applications. Refer to the [PHP Manual](https://www.php.net/manual/en/language.basic-syntax.php) for detailed syntax rules and examples. -::: - -## PHP Syntax Diagram - -```mermaid -graph TD - A(File Structure and Execution) --> B(PHP Tags) - B --> C(Canonical PHP Tags) - B --> D(Short-open Tags) - D --> E(Escaping from HTML) - A --> F(Basic Syntax) - F --> G(Statements) - F --> H(Expressions) - F --> I(Blocks) - A --> J(Case Sensitivity) -``` \ No newline at end of file diff --git a/docs/PHP/php-type-casting.md b/docs/PHP/php-type-casting.md deleted file mode 100644 index 7f14fe5d5..000000000 --- a/docs/PHP/php-type-casting.md +++ /dev/null @@ -1,360 +0,0 @@ ---- -id: php-type-casting -title: PHP - Type Casting -sidebar_label: PHP - Type Casting -sidebar_position: 16 -tags: [PHP, type casting] ---- - -# PHP - Type Casting - -The term "Type Casting" refers to the conversion of one type of data to another. Since PHP is a weakly typed language, the parser coerces certain data types into others while performing certain operations. For example, a string containing digits is converted to an integer if it is one of the operands involved in an addition operation. - -## Implicit Type Casting - -Here is an example of coercive or implicit type casting: - -```php - -``` - -In this case, $b is a string variable cast into an integer to enable addition. It will produce the following output: - -``` -c = 30 -``` - -Let's take another example where an integer variable $a is converted to a string for concatenation with a string variable: - -```php - -``` - -It will produce the following output: - -``` -c = 1020 -``` - -In addition to coercive type conversion, PHP provides ways to explicitly cast one type of data to another using type casting operators or functions. - -## Type Casting Operators - -To convert an expression of one type to another, you can use type casting operators. Here are some examples: - -- `(int)` or `(integer)` casts to an integer. -- `(bool)` or `(boolean)` casts to a boolean. -- `(float)` or `(double)` or `(real)` casts to a float. -- `(string)` casts to a string. -- `(array)` casts to an array. -- `(object)` casts to an object. - -### Casting to Integer - -You can convert a float value to an integer using `(int)`: - -```php - -``` - -It will produce the following output: - -``` -int(9) -``` - -The float value is not rounded to the nearest integer; instead, it returns the integer part. - -#### String to Integer Conversion - -The `(int)` operator also converts a string to an integer. If the string contains only digits, the conversion is straightforward: - -```php - -``` - -Output: - -``` -int(99) -``` - -Even if the string contains a floating-point number, `(int)` returns just the integer part. However, if the string is alphanumeric, the conversion behaves differently: - -- If the string starts with digits followed by non-numeric characters, only the initial digits are considered. -- If the string starts with non-numeric characters and digits are in the middle, the operator returns "0". - -```php - -``` - -Output: - -``` -int(10) -int(0) -``` - -### Casting to Float Type - -You can use `(float)` or `(double)` to explicitly convert to a float: - -```php - -``` - -Output: - -``` -float(100) -``` - -A string containing a valid numeric representation may also be cast to float using these operators. - -#### Handling Scientific Notation - -Strings with scientific notation can also be converted to float: - -```php - -``` - -Output: - -``` -float(12.3) -float(5.5E-5) -``` - -Non-numeric characters after the floating-point numbers are ignored. If the string starts with non-numeric characters, the conversion returns "0". - -### Casting to String Type - -You can cast expressions evaluating to floating-point or integer to string using `(string)`: - -```php - -``` - -Output: - -``` -string(3) "100" -string(4) "55.5" -``` - -### Casting to Bool Type - -Non-zero numbers (integer or float) cast to true with `(bool)`. A value of "0" returns false. Strings are always cast to true. - -```php - -``` - -Output: - -``` -bool(true) -bool(false) -bool(true) -``` - -## Type Casting Functions - -PHP includes built-in functions for type casting: - -- `intval()` -- `floatval()` -- `strval()` - -### The `intval()` Function - -This function gets the integer value of a variable. - -```php - -``` - -Output: - -``` -42 -4 -42 -34 -34 -34 -26 -26 -26 -0 -1 -``` - -### The `floatval()` Function - -This function gets the float value of an expression. - -```php - -``` - -Output: - -``` -42 -4.2 -42 -99.9 -0 -0 -1 -``` - -The `doubleval()` function is an alias of `floatval()` and returns similar results. - -### The `strval()` Function - -This function gets the string value of a variable. - -```php - -``` - -Output: - -``` -42 -4.2 -420000 - -1 -``` - -If the value being converted to a string is an object that implements the `__toString()` method, `strval()` uses that method. - -```php - -``` - -Output: - -``` -myclass -``` - -```mermaid -graph TD - A[Input Data] -->|Type Casting| B{Type Casting Operators} - B -->|Integer| C(int) - B -->|Boolean| D(bool) - B -->|Float| E(float) - B -->|String| F(string) - B -->|Array| G(array) - B -->|Object| H(object) - A -->|Type Casting| I((Type Casting Functions)) - I -->|Integer| J("intval()") - I -->|Float| K("floatval()") - I -->|String| L("strval()") -``` \ No newline at end of file diff --git a/docs/PHP/php-type-juggling.md b/docs/PHP/php-type-juggling.md deleted file mode 100644 index 401a06ffd..000000000 --- a/docs/PHP/php-type-juggling.md +++ /dev/null @@ -1,155 +0,0 @@ ---- -id: php-type-juggling -title: PHP - Type Juggling -sidebar_label: PHP - Type Juggling -sidebar_position: 17 -tags: [PHP, type juggling] ---- - -# PHP - Type Juggling - -PHP is known as a dynamically typed language. The type of a variable in PHP changes dynamically based on the value assigned to it. This feature is called "type juggling" in PHP. - -## Dynamic Typing in PHP - -In languages like C, C++, and Java, you need to declare the variable and its type before using it. However, in PHP, explicit type declaration of a variable is neither needed nor supported. The type of a PHP variable is decided by the value assigned to it, and not the other way around. - -Here's an example demonstrating type juggling in PHP: - -```php - -``` - -Output: - -``` -The variable $var is of string type -The variable $var is of integer type -The variable $var is of boolean type -The variable $var is of array type -``` - -In this example, the type of "$var" changes dynamically as per the value assigned to it. This behavior is characteristic of type juggling in PHP. - -## Type Juggling in Expressions - -Type juggling also occurs during the evaluation of expressions. For instance, when a string variable containing digits is involved in an addition operation, it is automatically converted to an integer: - -```php - -``` - -Output: - -``` -int(200) -``` - -## Handling Non-Numeric Strings - -If a string starts with digits, trailing non-numeric characters are ignored during calculations. However, a notice is issued by the PHP parser: - -```php - -``` - -Output: - -``` -int(200) - -PHP Warning: A non-numeric value encountered in /path/to/file.php on line X -``` - -## Type Casting vs Type Juggling - -It's important to note the difference between "type casting" and "type juggling" in PHP. - -- **Type Juggling**: PHP automatically converts types from one to another when necessary. For example, if an integer value is assigned to a variable, it becomes an integer. -- **Type Casting**: Type casting occurs when the user explicitly defines the data type in which they want to cast a variable. - -Here's an example demonstrating type casting operators: - -```php - -``` - -Output: - -``` -bool(true) -string(3) "100" -array(1) { - [0]=> - int(100) -} -object(stdClass)#1 (1) { - ["scalar"]=> - int(100) -} -``` - -Casting a variable to a string can also be done by enclosing it in double quotes: - -```php - -``` - -Output: - -``` -string(5) "100.5" -string(5) "100.5" -``` - -```mermaid -graph TD -A[Value Assignment] -->|Type Juggling| B{Type Juggling} -B -->|Integer| C(int) -B -->|Boolean| D(bool) -B -->|Float| E(float) -B -->|String| F(string) -B -->|Array| G(array) -B -->|Object| H(object) -A -->|Type Casting| I((Type Casting)) -I -->|Integer| J("intval()") -I -->|Float| K("floatval()") -I -->|String| L("strval()") -I -->|Boolean| M("boolval()") -I -->|Array| N(array) -I -->|Object| O((Object Cast)) -``` diff --git a/docs/PHP/php-var-dump.md b/docs/PHP/php-var-dump.md deleted file mode 100644 index d078461ed..000000000 --- a/docs/PHP/php-var-dump.md +++ /dev/null @@ -1,243 +0,0 @@ ---- -id: php-var_dump-function -title: PHP var_dump() Function -sidebar_label: PHP var_dump() Function -sidebar_position: 11 -tags: [PHP, var_dump, debugging] ---- - -# PHP var_dump() Function - -## Introduction - -One of the built-in functions in PHP is the `var_dump()` function. This function displays structured information such as type and the value of one or more expressions given as arguments to this function. - -```php -var_dump(mixed $value, mixed ...$values): void -``` - -This function returns all the public, private, and protected properties of the objects in the output. The dump information about arrays and objects is properly indented to show the recursive structure. - -For the built-in integer, float, and Boolean variables, the `var_dump()` function shows the type and value of the argument variable. - -## Examples - -### Example 1: Integer Variable - -For example, here is an integer variable: - -```php - -``` - -The dump information is as follows: - -``` -int(10) -``` - -### Example 2: Float Variable - -Let's see how it behaves for a float variable: - -```php - -``` - -The `var_dump()` function returns the following output: - -``` -float(10.25) -``` - -### Example 3: Boolean Variable - -If the expression is a Boolean value: - -```php - -``` - -It will produce the following output: - -``` -bool(true) -``` - -### Example 4: String Variable - -For a string variable, the `var_dump()` function returns the length of the string also. - -```php - -``` - -It will produce the following output: - -``` -string(11) "Hello World" -``` - -Here we can use the `
` HTML tag that displays preformatted text. Text in a `
` element is displayed in a fixed-width font, and the text preserves both the spaces and the line breaks.
-
-```php
-";
-   $x = "Hello World"; 
-   var_dump($x);  
-   echo "
"; -?> -``` - -It will produce the following output: - -``` -string(11) "Hello World" -``` - -### Example 5: Studying the Array Structure Using var_dump() - -The `var_dump()` function is useful to study the array structure. In the following example, we have an array with one of the elements of the array being another array. In other words, we have a nested array situation. - -```php - -``` - -It will produce the following output: - -``` -array(4) { - [0]=> - string(5) "Hello" - [1]=> - bool(false) - [2]=> - float(99.99) - [3]=> - array(3) { - [0]=> - int(10) - [1]=> - int(20) - [2]=> - int(30) - } -} -``` - -### Example 6: Associative Array - -Since `$x` is an indexed array in the previous example, the index starting with `0` along with its value is dumped. In case the array is an associative array, the key-value pair information is dumped. - -```php - 10, 2 => 20, 3 => 30) - ); - var_dump($x); -?> -``` - -Here, you will get the following output: - -``` -array(4) { - [0]=> - string(5) "Hello" - [1]=> - bool(false) - [2]=> - float(99.99) - [3]=> - array(3) { - [1]=> - int(10) - [2]=> - int(20) - [3]=> - int(30) - } -} -``` - -### Example 7: Object Properties - -The `var_dump()` function can also reveal the properties of an object representing a class. In the following example, we have declared a `Point` class with two private properties `x` and `y`. The class constructor initializes the object `p` with the parameters passed to it. - -The `var_dump()` function provides the information about the object properties and their corresponding values. - -```php -x = $x; - $this->y = $y; - } - } - - $p = new Point(4, 5); - var_dump($p); -?> -``` - -It will produce the following output: - -``` -object(Point)#1 (2) { - ["x":"Point":private]=> - int(4) - ["y":"Point":private]=> - int(5) -} -``` - -## Dumping All Defined Variables - -There is a similar built-in function for producing dump in PHP, named `get_defined_vars()`. - -```php -var_dump(get_defined_vars()); -``` - -It will dump all the defined variables to the browser. - -## Diagram - -```mermaid -graph TD - A[Start] --> B["var_dump()"] - B --> C[Displays type and value] - C --> D[Handles multiple arguments] - C --> E[Returns void] - D --> F[Indentation for arrays and objects] - E --> G[Public, private, and protected properties] - G --> H[Integers, floats, and Booleans show type and value] - H --> I[Strings show type, value, and length] - I --> J[Arrays show recursive structure] - J --> K[Objects show properties and values] -``` - -:::note - -Understanding the `var_dump()` function helps in debugging and studying the structure of variables in PHP. It's an essential tool for PHP developers to inspect and debug their code. - -::: \ No newline at end of file diff --git a/docs/PHP/php-variables.md b/docs/PHP/php-variables.md deleted file mode 100644 index bb650075a..000000000 --- a/docs/PHP/php-variables.md +++ /dev/null @@ -1,168 +0,0 @@ ---- -id: php-variables -title: PHP - Variables -sidebar_label: PHP - Variables -sidebar_position: 9 -tags: [PHP, variables, web development] ---- - -# PHP - Variables - -## Introduction - -A variable in PHP is a named memory location that holds data belonging to one of the data types. PHP uses the convention of prefixing a dollar sign (`$`) to the name of a variable. Variable names in PHP are case-sensitive and follow the same rules as other labels in PHP. - -### Variable Naming - -A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. Examples of valid variable names in PHP are: - -- `$name` -- `$rate_of_int` -- `$Age` -- `$mark1` - -Examples of invalid variable names are: - -- `name` (not having `$` prefix) -- `$rate of int` (whitespace not allowed) -- `$Age#1` (invalid character `#`) -- `$11` (name not starting with alphabet) - -### Variable Assignment - -Variables are assigned with the `=` operator, with the variable on the left-hand side and the expression to be evaluated on the right. - -## Dynamic Typing in PHP - -PHP is a dynamically typed language, meaning there is no need to specify the type of a variable. The type of a variable is decided by the value assigned to it. The value of a variable is the value of its most recent assignment. - -```php - -``` - -It will produce the following output: - -``` -Data type of x: integer -Data type of x now: double -``` - -## Automatic Type Conversion - -PHP does a good job of automatically converting types from one to another when necessary. - -```php - -``` - -It will produce the following output: - -``` -x + y is: 30 -``` - -## Variables Assignment - -### Assigned by Value - -In PHP, variables are always assigned by value. If an expression is assigned to a variable, the value of the original expression is copied into it. Changes to the original variable after assignment do not affect the copied value. - -```php - -``` - -It will produce the following output: - -``` -(before) z = 30 -(after) z = 30 -``` - -### Assigned by Reference - -You can also assign values to PHP variables by reference. The new variable references or points to the original variable. Changes to the new variable affect the original and vice versa. - -```php - -``` - -It will produce the following output: - -``` -x = 10 y = 10 z = 20 -x = 20 y = 20 z = 40 -``` - -## Variable Scope - -Scope defines the range of availability a variable has to the program in which it is declared. PHP variables can have one of four scope types: - -- Local Variables -- Global Variables -- Static Variables -- Function Parameters - -## Variable Naming Rules - -- Variable names must begin with a letter or underscore character. -- A variable name can consist of numbers, letters, and underscores but cannot contain characters like `+`, `-`, `%`, `(`, `)`, `.` , `&`, etc. -- There is no size limit for variable names. - -## PHP Variables Diagram - -```mermaid -graph TD - A[Variable Declaration] --> B[Variable Naming] - A --> C[Variable Assignment] - B --> D[Valid Names] - B --> E[Invalid Names] - C --> F[Assigned by Value] - C --> G[Assigned by Reference] - A --> H[Variable Scope] - H --> I[Local Variables] - H --> J[Global Variables] - H --> K[Static Variables] - H --> L[Function Parameters] -``` - -:::note - -Understanding variable types, naming conventions, and scope is crucial for effective PHP programming. This knowledge helps in writing clear, maintainable, and bug-free code. -::: - -## Table of PHP Variable Types - -| Variable Type | Description | -|-----------------------|-----------------------------------------------------| -| Local Variables | Declared inside a function, accessible only within that function | -| Global Variables | Declared outside of any function, accessible globally | -| Static Variables | Retain their value even after the function exits | -| Function Parameters | Variables passed to a function | diff --git a/docs/css/colors/_category_.json b/docs/css/colors/_category_.json new file mode 100644 index 000000000..cc37574c5 --- /dev/null +++ b/docs/css/colors/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Colors", + "position": 3, + "link": { + "type": "generated-index", + "description": "In this section, you will learn about the CSS Colors. CSS colors are used to specify the color of the text, backgrounds, borders, and other elements on a web page. You can specify colors using different methods such as color names, HEX values, RGB values, HSL values, and more." + } + } \ No newline at end of file diff --git a/docs/css/colors/color-names.md b/docs/css/colors/color-names.md index e69de29bb..a1bae0ec3 100644 --- a/docs/css/colors/color-names.md +++ b/docs/css/colors/color-names.md @@ -0,0 +1,200 @@ +--- +id: color-names +title: Color Names +sidebar_label: Color Names +tags: [color, css, color-names] +description: Color names are predefined names for colors that can be used in CSS to style elements. +keywords: + [ + color names, + css color names, + css colors, + css color names list, + ] +sidebar_position: 1 +--- + +In CSS, color names are predefined names for colors that can be used to style elements. Color names provide an easy way to specify colors in CSS without having to remember the hexadecimal (hex) or RGB values of the colors. There are 147 color names that are supported by all major browsers, and they can be used to set the color of text, backgrounds, borders, and other CSS properties. + + + +## Syntax + +The syntax for using color names in CSS is as follows: + +```css title="index.css" +selector { + color: color-name; +} +``` + +- `selector`: The element to which the color is applied. +- `color`: The CSS property used to set the color of the text. +- `color-name`: The predefined name of the color. +- The color name is used to specify the color of the text, background, border, or other CSS properties. + +## Example + +In the following example, the color name `red` is used to set the color of the text to red: + +```css title="index.css" +h1 { + color: red; +} +``` + +In the HTML code below, the CSS rule will set the color of the `

` element to red: + +```html title="index.html" +

This is a heading

+``` + +:::info Additional Information + +- Color names provide an easy way to specify colors in CSS. +- There are 147 color names that are supported by all major browsers. +- Color names can be used to set the color of text, backgrounds, borders, and other CSS properties. +- Color names are case-insensitive, meaning you can use uppercase, lowercase, or a combination of both when specifying color names. +- Color names are an alternative to using hexadecimal (hex) or RGB values to specify colors in CSS. +- Color names are useful for quickly setting the color of elements without having to remember specific color codes. +- Color names are easy to remember and can be used to create visually appealing designs in CSS. +- Color names are supported by all major browsers and provide a consistent way to specify colors across different platforms. + +::: + + + +### List of Common Color Names + +Here are some common CSS color names: + +- **Basic Colors**: `red`, `blue`, `green`, `yellow`, `black`, `white`, `gray` +- **Shades of Red**: `darkred`, `firebrick`, `indianred`, `tomato`, `lightcoral` +- **Shades of Blue**: `dodgerblue`, `deepskyblue`, `skyblue`, `lightblue`, `steelblue` +- **Shades of Green**: `forestgreen`, `darkgreen`, `lightgreen`, `lime`, `darkolivegreen` +- **Other Colors**: `gold`, `silver`, `peachpuff`, `plum`, `chocolate`, `orchid`, `coral` + +You can use these color names in your CSS stylesheets to set the color of elements and create visually appealing designs. Color names provide a convenient way to specify colors in CSS and make it easier to work with colors in web development projects. + + + +### Example: Using Color Names + +In the following example, the color name `blue` is used to set the color of the text to blue: + + + +```html title="index.html" + + + + + + Color Names Example + + + +

Welcome to Color Names

+

This is an example of using color names in CSS.

+ + +``` +
+ +```css title="styles.css" +h1 { + color: blue; +} + +p { + color: darkred; +} +``` + + +
+ +Now, you can see the output of the above code in the Browser Window like this: + + +
+

Welcome to Color Names

+

This is an example of using color names in CSS.

+
+
+ +In this example, the color names `blue` and `darkred` are used to set the color of the `

` and `

` elements, respectively. The `

` element will have blue text, while the `

` element will have dark red text. + +Color names are a convenient way to specify colors in CSS and can be used to create visually appealing designs in web development projects. + + + +:::note Extra Information +**1. How many way to use color in CSS?** + - There are several ways to specify colors in CSS: + - Using color names: Predefined names for colors (e.g., `red`, `blue`, `green`). + - Using hexadecimal (hex) values: A six-digit code that represents the RGB values of a color (e.g., `#ff0000` for red). + - Using RGB values: An RGB color value is specified with the `rgb()` function, which takes three parameters (e.g., `rgb(255, 0, 0)` for red). + - Using RGBA values: An RGBA color value is specified with the `rgba()` function, which takes four parameters (e.g., `rgba(255, 0, 0, 0.5)` for red with 50% opacity). + - Using HSL values: An HSL color value is specified with the `hsl()` function, which takes three parameters (e.g., `hsl(0, 100%, 50%)` for red). + - Using HSLA values: An HSLA color value is specified with the `hsla()` function, which takes four parameters (e.g., `hsla(0, 100%, 50%, 0.5)` for red with 50% opacity). + +**2. What are the advantages of using color names in CSS?** + + - Color names provide an easy and intuitive way to specify colors in CSS. + - Color names are easy to remember and use, making it convenient to work with colors in web development projects. + - Color names are supported by all major browsers, ensuring consistent color rendering across different platforms. + - Color names can be used to set the color of text, backgrounds, borders, and other CSS properties. + - Color names are an alternative to using hexadecimal (hex) or RGB values to specify colors in CSS. + - Color names are useful for quickly setting the color of elements without having to remember specific color codes. + - Color names can be combined with other CSS properties to create visually appealing designs in web development projects. + +**3. Are color names case-sensitive in CSS?** + + - No, color names are case-insensitive in CSS, meaning you can use uppercase, lowercase, or a combination of both when specifying color names. + - For example, `red`, `RED`, and `Red` are all valid ways to specify the color red using the color name in CSS. + - Color names are not case-sensitive, so you can use any combination of uppercase and lowercase letters when specifying color names in CSS. + +**4. Can color names be used with other CSS properties?** + + - Yes, color names can be used with other CSS properties to style elements in web pages. + - Color names can be combined with properties like `background-color`, `border-color`, `text-decoration`, and more to create visually appealing designs. + - Color names can be used to set the color of text, backgrounds, borders, and other CSS properties in web development projects. + - By using color names with other CSS properties, you can customize the appearance of elements and create engaging user interfaces. + +**5. How many color names are supported in CSS?** + + - There are 147 color names that are supported by all major browsers in CSS. + - These color names provide a wide range of colors that can be used to style elements in web pages. + - Color names are a convenient way to specify colors in CSS and make it easier to work with colors in web development projects. + - Color names are supported by all major browsers, ensuring consistent color rendering across different platforms. + +**6. Can color names be used in combination with other color values in CSS?** + + - Yes, color names can be used in combination with other color values like hexadecimal (hex), RGB, RGBA, HSL, and HSLA values in CSS. + - Color names can be combined with other color values to create complex color schemes and gradients in web development projects. + - By using color names in combination with other color values, you can achieve a wide range of colors and effects in your CSS stylesheets. + - Color names provide a simple and intuitive way to work with colors in CSS and can be easily combined with other color values to create visually appealing designs. + +**7. Are color names supported by all browsers?** + + - Yes, color names are supported by all major browsers, including Chrome, Firefox, Safari, Edge, and Opera. + - Color names provide a consistent way to specify colors in CSS across different platforms and ensure that colors are rendered correctly in web pages. + - Color names are widely supported and can be used to set the color of text, backgrounds, borders, and other CSS properties in web development projects. + - By using color names, you can create visually appealing designs that are consistent across different browsers and devices. + +**8. How can color names be used to create visually appealing designs in CSS?** + + - Color names can be used to set the color of text, backgrounds, borders, and other CSS properties in web pages. + - By combining color names with other CSS properties like `background-color`, `border-color`, `text-decoration`, and more, you can create visually appealing designs. + - Color names provide a simple and intuitive way to work with colors in CSS and make it easy to create engaging user interfaces. + - Color names can be used to create color schemes, gradients, and effects that enhance the visual appeal of web pages. + - By using color names creatively in your CSS stylesheets, you can design attractive and user-friendly interfaces for your web development projects. + +::: + +By using color names in CSS, you can easily set the color of elements in your web pages and create visually appealing designs. Color names provide a simple and intuitive way to work with colors in CSS and are supported by all major browsers. + +## Conclusion + +Color names are predefined names for colors that can be used in CSS to style elements. By using color names, you can specify the color of text, backgrounds, borders, and other CSS properties without having to remember specific color codes. Color names provide a convenient way to work with colors in CSS and make it easier to create visually appealing designs in web development projects. \ No newline at end of file diff --git a/docs/css/colors/hex.md b/docs/css/colors/hex.md index e69de29bb..f8df82d40 100644 --- a/docs/css/colors/hex.md +++ b/docs/css/colors/hex.md @@ -0,0 +1,180 @@ +--- +id: hex +title: Hex Color Values +sidebar_label: Hex Color Values +tags: [color, hex, css color, hex color] +description: Hex color values are used to specify colors in CSS using hexadecimal notation. +keywords: + [ + hex color values, + css hex color values, + css color values, + hex color, + ] +sidebar_position: 3 +--- + +In CSS, hex color values are used to specify colors using hexadecimal notation. Hex color values are represented by a `#` character followed by a six-digit hexadecimal number. The hexadecimal number is composed of three pairs of digits, each pair representing the intensity of the red, green, and blue color channels, respectively. Hex color values allow you to specify a wide range of colors by adjusting the intensity of the red, green, and blue color channels. + + + +## Syntax + +The syntax for hex color values is as follows: + +```css title="index.css" +selector { + color: #RRGGBB; +} +``` + +- `selector`: The element to which the hex color value is applied. +- `color`: The CSS property used to specify the color of an element. +- `#`: The `#` character represents the hex color value. +- `RR`: The intensity of the red color channel (00 to FF). +- `GG`: The intensity of the green color channel (00 to FF). +- `BB`: The intensity of the blue color channel (00 to FF). + +:::info Additional Information +**1. Hexadecimal Notation:** Hex color values are represented using hexadecimal notation, which allows you to specify colors using a combination of numbers and letters. (0-9, A-F) + +**2. Color Channels:** Hex color values consist of three pairs of digits, each pair representing the intensity of the red, green, and blue color channels, respectively. + +**3. Wide Range of Colors:** Hex color values allow you to create a wide range of colors by adjusting the intensity of the red, green, and blue color channels. + +**4. Shortened Hex Values:** Hex color values can be shortened if the three pairs of digits are the same. For example, `#FF0000` can be shortened to `#F00` for red. + +**5. Transparency:** Hex color values can also include an additional pair of digits to represent the alpha channel for transparency. For example, `#RRGGBBAA` represents a color with transparency. + +**6. Browser Support:** Hex color values are widely supported by all modern web browsers. + +**7. Color Picker Tools:** There are online tools and color picker applications that allow you to choose colors and generate their corresponding hex values. + +By using hex color values, you can easily specify colors in CSS and create visually appealing designs for your web pages. + +::: + + + +## Example + +In the following example, the hex color value `#FF0000` is used to specify the color of a `

` element as red: + +```css title="index.css" +h1 { + color: #FF0000; /* Red color */ +} +``` + +In the HTML code below, the CSS rule will apply the red color to the `

` element: + +```html title="index.html" +

This is a red heading.

+``` + +By adjusting the hex color value, you can create different colors for your elements in CSS. Hex color values provide a convenient way to specify colors and customize the appearance of your web pages. + +## Hex Color Shorthand + +Hex color values can be shortened if the three pairs of digits are the same. For example, the hex color value `#FF0000` can be shortened to `#F00` for red. This shorthand notation allows you to specify colors more concisely and reduces the length of the hex color value. + +### Example + +In the following example, the hex color value `#F00` is used to specify the color of a `

` element as red: + +```css title="index.css" +p { + color: #F00; /* Red color */ +} +``` + +In the HTML code below, the CSS rule will apply the red color to the `

` element: + +```html title="index.html" +

This is a red paragraph.

+``` + +By using the shorthand notation for hex color values, you can write CSS code more efficiently and make it easier to specify colors in your stylesheets. + + + +## Transparency with Hex Color Values + +Hex color values can include an additional pair of digits to represent the alpha channel for transparency. The alpha channel specifies the opacity of the color, allowing you to create semi-transparent colors in CSS. Hex color values with transparency are represented by eight digits: `#RRGGBBAA`, where `AA` represents the alpha channel value. + +### Example + +In the following example, the hex color value `#FF0000CC` is used to specify a semi-transparent red color for a `
` element: + +```css title="index.css" +div { + background-color: #FF0000CC; /* Semi-transparent red color */ +} +``` + +In the HTML code below, the CSS rule will apply the semi-transparent red color to the background of the `
` element: + +```html title="index.html" +
This is a semi-transparent red div.
+``` + +By using hex color values with transparency, you can create visually appealing effects and overlay colors with varying levels of opacity in your web designs. + +## Example: Using Hex Color Values + +In the following example, hex color values are used to specify the colors of different elements in a web page: + + + + +```html title="index.html" + + + + + + Hex Color Values Example + + + +

This is a red heading.

+

This is a blue paragraph.

+
This is a semi-transparent green div.
+ + +``` + +
+ + +```css title="styles.css" +h1 { + color: #FF0000; /* Red color */ +} + +p { + color: #0000FF; /* Blue color */ +} + +div { + background-color: #00FF00AA; /* Semi-transparent green color */ +} +``` + +
+ +Now, you can see the output of the above code in the Browser Window like this: + + +
+

This is a red heading.

+

This is a blue paragraph.

+
This is a semi-transparent green div.
+
+
+ +In this example, the hex color values `#FF0000`, `#0000FF`, and `#00FF00AA` are used to specify the colors of the `

`, `

`, and `

` elements, respectively. The `

` element is styled with a red color, the `

` element with a blue color, and the `

` element with a semi-transparent green background color. + +## Conclusion + +Hex color values are a popular way to specify colors in CSS using hexadecimal notation. By using hex color values, you can create a wide range of colors by adjusting the intensity of the red, green, and blue color channels. Hex color values provide a convenient and efficient method for specifying colors in your stylesheets and customizing the appearance of your web pages. With the ability to include transparency, hex color values offer additional flexibility in creating visually appealing designs for your websites. \ No newline at end of file diff --git a/docs/css/colors/rgb.md b/docs/css/colors/rgb.md index e69de29bb..7c346da49 100644 --- a/docs/css/colors/rgb.md +++ b/docs/css/colors/rgb.md @@ -0,0 +1,131 @@ +--- +id: rgb +title: RGB Color Values +sidebar_label: RGB Color Values +tags: [color, rgb, css color, rgb color] +description: RGB color values are used to specify colors in CSS using the red, green, and blue color channels. +keywords: + [ + rgb color values, + css rgb color values, + css color values, + rgb color, + ] +sidebar_position: 2 +--- + +In CSS, RGB color values are used to specify colors using the red, green, and blue color channels. RGB color values are represented by the `rgb()` function, which takes three arguments: the red, green, and blue color channels. Each color channel is represented by an integer value between 0 and 255, where 0 represents no color and 255 represents the maximum intensity of the color channel. + + + +## Syntax + +The syntax for RGB color values is as follows: + +```css title="index.css" +selector { + color: rgb(red, green, blue); +} +``` + +- `selector`: The element to which the RGB color value is applied. +- `color`: The CSS property used to specify the color of an element. +- `rgb()`: The function used to specify RGB color values. +- `red`: The intensity of the red color channel (0 to 255). +- `green`: The intensity of the green color channel (0 to 255). +- `blue`: The intensity of the blue color channel (0 to 255). + +## Example + +In the following example, the `rgb()` function is used to specify the color of a `
` element using RGB color values: + +```css title="index.css" +div { + color: rgb(255, 0, 0); /* Red color */ +} +``` + +In the HTML code below, the CSS rule will apply the red color to the `
` element: + +```html title="index.html" +
This is a red div.
+``` + +:::info Additional Information + +- RGB color values are represented by the `rgb()` function in CSS. +- RGB color values are specified using the red, green, and blue color channels. +- Each color channel is represented by an integer value between 0 and 255. +- RGB color values allow you to create a wide range of colors by adjusting the intensity of the red, green, and blue color channels. + +::: + +## RGB Color Channels + +The RGB color model uses three color channels—red, green, and blue—to create a wide range of colors. Each color channel has an intensity value between 0 and 255, where 0 represents no color and 255 represents the maximum intensity of the color channel. By combining different intensities of the red, green, and blue color channels, you can create millions of unique colors. + +### Red Color Channel + +The red color channel controls the intensity of red in the color. A value of 0 indicates no red color, while a value of 255 represents the maximum intensity of red. + +### Green Color Channel + +The green color channel controls the intensity of green in the color. A value of 0 indicates no green color, while a value of 255 represents the maximum intensity of green. + +### Blue Color Channel + +The blue color channel controls the intensity of blue in the color. A value of 0 indicates no blue color, while a value of 255 represents the maximum intensity of blue. + +By adjusting the intensity of each color channel, you can create a wide variety of colors in the RGB color model. + + + +## Example: Using RGB Color Values + +In the following example, the `rgb()` function is used to specify the color of a `` element using RGB color values: + + + + +```html title="index.html" + + + + + + RGB Color Example + + + + This is red text. + + +``` + + + + +```css title="styles.css" +span.red-text { + color: rgb(255, 0, 0); /* Red color */ +} +``` + + + + +Now, you can see the output of the above code in the Browser Window like this: + + +
+ This is red text. +
+
+ +In this example, the `rgb(255, 0, 0)` value is used to specify the color of the `` element as red. The text inside the `` element is displayed in red color on the web page. + +RGB color values are commonly used in CSS to specify colors for text, backgrounds, borders, and other elements on a web page. By adjusting the intensity of the red, green, and blue color channels, you can create a wide range of colors to style your web pages. + +## Conclusion + +RGB color values are a fundamental part of CSS that allow you to specify colors using the red, green, and blue color channels. By adjusting the intensity of each color channel, you can create millions of unique colors to style your web pages. RGB color values are versatile and widely used in web development to create visually appealing designs and user interfaces. \ No newline at end of file diff --git a/docs/css/colors/rgba.md b/docs/css/colors/rgba.md index e69de29bb..9aae73354 100644 --- a/docs/css/colors/rgba.md +++ b/docs/css/colors/rgba.md @@ -0,0 +1,119 @@ +--- +id: rgba +title: RGBA Color Values +sidebar_label: RGBA Color Values +tags: [color, rgba, css color, rgba color] +description: RGBA color values are used to specify colors in CSS using the red, green, blue, and alpha color channels. +keywords: + [ + rgba color values, + css rgba color values, + css color values, + rgba color, + ] +sidebar_position: 4 +--- + +In CSS, RGBA color values are used to specify colors using the red, green, blue, and alpha color channels. RGBA color values are represented by the `rgba()` function, which takes four arguments: the red, green, blue, and alpha color channels. The red, green, and blue color channels are represented by integer values between 0 and 255, where 0 represents no color and 255 represents the maximum intensity of the color channel. The alpha channel is represented by a decimal value between 0 and 1, where 0 represents full transparency and 1 represents full opacity. + + + +## Syntax + +The syntax for RGBA color values is as follows: + +```css title="index.css" +selector { + color: rgba(red, green, blue, alpha); +} +``` + +- `selector`: The element to which the RGBA color value is applied. +- `color`: The CSS property used to specify the color of an element. +- `rgba()`: The function used to specify RGBA color values. +- `red`: The intensity of the red color channel (0 to 255). +- `green`: The intensity of the green color channel (0 to 255). +- `blue`: The intensity of the blue color channel (0 to 255). +- `alpha`: The transparency of the color (0 to 1). + +## Example + +In the following example, the `rgba()` function is used to specify the color of a `
` element using RGBA color values with partial transparency: + +```css title="index.css" +div { + color: rgba(255, 0, 0, 0.5); /* Red color with 50% transparency */ +} +``` + +In the HTML code below, the CSS rule will apply the red color with 50% transparency to the `
` element: + +```html title="index.html" +
This is a partially transparent red div.
+``` + +:::info Additional Information + +- RGBA color values are represented by the `rgba()` function in CSS. +- RGBA color values are specified using the red, green, blue, and alpha color channels. +- The red, green, and blue color channels are represented by integer values between 0 and 255. +- The alpha channel is represented by a decimal value between 0 and 1. +- RGBA color values allow you to create colors with varying levels of transparency. +- RGBA color values are widely supported by all modern web browsers. + +::: + +## RGBA Color Channels + +The RGBA color model is an extension of the RGB color model that includes an additional alpha channel for transparency. The alpha channel specifies the opacity of the color, allowing you to create colors with varying levels of transparency. The alpha channel is represented by a decimal value between 0 and 1, where 0 represents full transparency and 1 represents full opacity. + +The RGBA color model is commonly used in web design to create visually appealing designs with elements that have varying levels of transparency. + + + +## Example with Gradient Background + +In the following example, the `rgba()` function is used to create a gradient background for a `
` element with varying levels of transparency: + + + + +```html title="index.html" + + + + + + RGBA Gradient Background Example + + + +
This is a gradient background with transparency.
+ + +``` + +
+ + +```css title="styles.css" +div { + background: linear-gradient(rgba(255, 0, 0, 1), rgba(255, 0, 0, 0)); + color: white; + padding: 20px; + text-align: center; +} +``` + + +
+ +Now, you can see the output of the above code in the Browser Window like this: + + +
+ This is a gradient background with transparency. +
+
+ +In this example, the `linear-gradient()` function is used to create a gradient background that transitions from a fully opaque red color at the top to a fully transparent red color at the bottom of the `
` element. \ No newline at end of file From 0d1ed3cb55380a381df7a0ee41ad3e2d7726d90c Mon Sep 17 00:00:00 2001 From: Ajay-Dhangar Date: Sun, 26 Jan 2025 22:15:31 +0530 Subject: [PATCH 2/2] css content on working --- docs/css/colors/rgba.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/css/colors/rgba.md b/docs/css/colors/rgba.md index 9aae73354..0b4f07fb6 100644 --- a/docs/css/colors/rgba.md +++ b/docs/css/colors/rgba.md @@ -116,4 +116,18 @@ Now, you can see the output of the above code in the Browser Window like this:
-In this example, the `linear-gradient()` function is used to create a gradient background that transitions from a fully opaque red color at the top to a fully transparent red color at the bottom of the `
` element. \ No newline at end of file +In this example, the `linear-gradient()` function is used to create a gradient background that transitions from a fully opaque red color at the top to a fully transparent red color at the bottom of the `
` element. + +:::info Additional Information + +- The `linear-gradient()` function is used to create a gradient background in CSS. +- The `rgba()` function is used to specify colors with varying levels of transparency. +- The `linear-gradient()` function can be used to create gradients with multiple color stops and directions. +- The `rgba()` function allows you to create visually appealing designs with elements that have varying levels of transparency. +- The RGBA color model is widely supported by all modern web browsers. + +::: + +## Conclusion + +RGBA color values are a powerful tool in CSS that allow you to create visually appealing designs with elements that have varying levels of transparency. By using the red, green, blue, and alpha color channels, you can create colors with precise levels of transparency to achieve the desired visual effect. RGBA color values are widely supported by all modern web browsers and are commonly used in web design to create gradient backgrounds, text shadows, and other visual effects. \ No newline at end of file