diff --git a/docs/MongoDB/Advanced MongoDB/mongodb-ObjectId.md b/docs/MongoDB/Advanced MongoDB/mongodb-ObjectId.md new file mode 100644 index 000000000..4957ddf28 --- /dev/null +++ b/docs/MongoDB/Advanced MongoDB/mongodb-ObjectId.md @@ -0,0 +1,69 @@ +--- +id: mongodb-ObjectId +title: MongoDB - ObjectId +sidebar_label: ObjectId +sidebar_position: 8 +tags: [mongodb, ObjectId, document identifier] +description: Understand the structure and usage of ObjectId in MongoDB, including creation, timestamp extraction, and conversion to string format. +--- + +We have been using MongoDB ObjectId in all the previous chapters. In this chapter, let's delve into the structure and usage of ObjectId. + +## ObjectId Structure + +An ObjectId is a 12-byte BSON type structured as follows: + +- The first 4 bytes represent the seconds since the Unix epoch. +- The next 3 bytes are the machine identifier. +- The following 2 bytes consist of the process id. +- The last 3 bytes are a random counter value. + +MongoDB utilizes ObjectIds as the default value of the `_id` field of each document, generated during document creation. This intricate combination ensures that all `_id` fields are unique. + +## Creating New ObjectId + +To generate a new ObjectId, use the following code snippet: + +```javascript +newObjectId = ObjectId() +``` + +The above statement will return a uniquely generated id like: + +``` +ObjectId("5349b4ddd2781d08c09890f3") +``` + +Alternatively, you can provide a 12-byte id explicitly: + +```javascript +myObjectId = ObjectId("5349b4ddd2781d08c09890f4") +``` + +## Creating Timestamp of a Document + +As the `_id` ObjectId inherently stores the 4-byte timestamp, you typically don't need to store the creation time of any document separately. You can retrieve the creation time of a document using the `getTimestamp` method: + +```javascript +ObjectId("5349b4ddd2781d08c09890f4").getTimestamp() +``` + +This will return the creation time of the document in ISO date format: + +``` +ISODate("2014-04-12T21:49:17Z") +``` + +## Converting ObjectId to String + +In certain scenarios, you may require the ObjectId value in a string format. To convert the ObjectId to a string, use the following code: + +```javascript +newObjectId.str +``` + +The above code will provide the string format of the ObjectId, such as: + +``` +5349b4ddd2781d08c09890f3 +``` diff --git a/docs/MongoDB/Advanced MongoDB/mongodb-indexing-limitations.md b/docs/MongoDB/Advanced MongoDB/mongodb-indexing-limitations.md new file mode 100644 index 000000000..232eef715 --- /dev/null +++ b/docs/MongoDB/Advanced MongoDB/mongodb-indexing-limitations.md @@ -0,0 +1,109 @@ +--- +id: mongodb-indexing-limitations +title: MongoDB - Indexing Limitations +sidebar_label: Indexing Limitations +sidebar_position: 7 +tags: [mongodb, indexing, limitations, performance] +description: Understand the limitations of indexing in MongoDB, including overhead, RAM usage, query constraints, and key limits. +--- + +# MongoDB - Indexing Limitations + +In this chapter, we will learn about Indexing Limitations and its other components. + +## Extra Overhead + +Every index occupies some space as well as causes an overhead on each insert, update and delete. So if you rarely use your collection for read operations, it makes sense not to use indexes. + +:::note +- Indexes require additional space. +- Each insert, update, and delete operation requires additional processing due to index maintenance. +::: + +```mermaid +graph TD; + A[Insert Operation] --> B[Index Overhead]; + C[Update Operation] --> B; + D[Delete Operation] --> B; +``` + +## RAM Usage + +Since indexes are stored in RAM, you should make sure that the total size of the index does not exceed the RAM limit. If the total size increases the RAM size, it will start deleting some indexes, causing performance loss. + +:::note + Ensure that the total size of all indexes does not exceed the available RAM to avoid performance issues. +::: + +```mermaid +graph TD; + A[Indexes] -->|Stored in| B[RAM]; + B -->|Exceeds| C[Performance Loss]; + C --> D[Deletes Some Indexes]; +``` + +## Query Limitations + +Indexing can't be used in queries which use: +- Regular expressions or negation operators like `$nin`, `$not`, etc. +- Arithmetic operators like `$mod`, etc. +- `$where` clause + +:::note +- Regular expressions and negation operators cannot use indexes. +- Arithmetic operators and `$where` clause cannot use indexes. +::: + +| Query Type | Index Usage | +|-----------------|--------------| +| Regular Expressions | Not Supported | +| Negation Operators | Not Supported | +| Arithmetic Operators | Not Supported | +| `$where` Clause | Not Supported | + +## Index Key Limits + +Starting from version 2.6, MongoDB will not create an index if the value of existing index field exceeds the index key limit. + +> **Note:** Index creation is restricted if any field value exceeds the index key limit. + +```mermaid +graph TD; + A[Index Creation] -->|Value exceeds limit| B[Not Created]; +``` + +## Inserting Documents Exceeding Index Key Limit + +MongoDB will not insert any document into an indexed collection if the indexed field value of this document exceeds the index key limit. The same is the case with `mongorestore` and `mongoimport` utilities. + +:::note + Documents with indexed field values exceeding the key limit will not be inserted into an indexed collection. +::: + +```mermaid +graph TD; + A[Document Insertion] -->|Exceeds Key Limit| B[Insertion Failed]; + C[mongorestore] -->|Exceeds Key Limit| B; + D[mongoimport] -->|Exceeds Key Limit| B; +``` + +## Maximum Ranges + +- A collection cannot have more than 64 indexes. +- The length of the index name cannot be longer than 125 characters. +- A compound index can have a maximum of 31 fields indexed. + +> **Table: Maximum Ranges** + +| Limit Type | Maximum Value | +|--------------------------|---------------------| +| Number of Indexes | 64 | +| Length of Index Name | 125 Characters | +| Fields in Compound Index | 31 Fields | + +```mermaid +graph TD; + A[Maximum Ranges] --> B[64 Indexes per Collection]; + A --> C[125 Characters Index Name]; + A --> D[31 Fields in Compound Index]; +``` diff --git a/docs/MongoDB/Advanced MongoDB/mongodb-map-reduce.md b/docs/MongoDB/Advanced MongoDB/mongodb-map-reduce.md new file mode 100644 index 000000000..b026fdd61 --- /dev/null +++ b/docs/MongoDB/Advanced MongoDB/mongodb-map-reduce.md @@ -0,0 +1,109 @@ +--- +id: mongodb-map-reduce +title: MongoDB - Map Reduce +sidebar_label: Map Reduce +sidebar_position: 9 +tags: [mongodb, map reduce, data processing] +description: Understand the MapReduce paradigm in MongoDB for condensing large volumes of data into useful aggregated results. +--- + +According to MongoDB documentation, MapReduce is a data processing paradigm used to condense large data sets into useful aggregated results. MongoDB employs the `mapReduce` command for map-reduce operations, primarily for processing substantial data sets. + +## MapReduce Command Syntax + +The basic syntax of the `mapReduce` command in MongoDB is as follows: + +```javascript +db.collection.mapReduce( + function() {emit(key,value);}, // map function + function(key,values) {return reduceFunction;}, // reduce function + { // options + out: collection, // specifies the location of the query result + query: document, // optional selection criteria for documents + sort: document, // optional sort criteria + limit: number // optional maximum number of documents to return + } +) +``` + +In the above syntax: + +- `map` is a JavaScript function that maps a value with a key and emits a key-value pair. +- `reduce` is a JavaScript function that reduces or groups documents with the same key. +- `out` specifies the location of the map-reduce query result. +- `query` specifies optional selection criteria for selecting documents. +- `sort` specifies optional sort criteria. +- `limit` specifies the optional maximum number of documents to return. + +### Using MapReduce + +Consider a document structure storing user posts with fields like `post_text`, `user_name`, and `status`. We will perform a mapReduce function to select active posts, group them by `user_name`, and count the number of posts by each user. + +```javascript +db.posts.mapReduce( + function() { emit(this.user_name, 1); }, + function(key, values) { return Array.sum(values); }, + { + query: { status: "active" }, + out: "post_total" + } +) +``` + +The above mapReduce query outputs the following result: + +```json +{ + "result" : "post_total", + "timeMillis" : 9, + "counts" : { + "input" : 4, + "emit" : 4, + "reduce" : 2, + "output" : 2 + }, + "ok" : 1 +} +``` + +To see the result of this mapReduce query, you can use the `find` operator: + +```javascript +db.post_total.find() +``` + +This query will return results showing the count of active posts for each user: + +```json +{ "_id" : "tom", "value" : 2 } +{ "_id" : "mark", "value" : 2 } +``` + +MapReduce queries in MongoDB are powerful for constructing complex aggregation queries using custom JavaScript functions, providing flexibility in data processing and analysis. + +### Diagram: MapReduce Process + +```mermaid +graph TD; + A[Query Collection] --> B(Map Function); + B --> C(Emit Key-Value Pairs); + C --> D(Reduce Function); + D --> E(Aggregated Results); +``` + +:::note Performance Considerations + +When using MapReduce in MongoDB: +- Consider the performance overhead, especially for large data sets. +- Optimize your map and reduce functions for efficiency. +- Utilize indexes to improve query performance. +::: + +### Table: MapReduce Options + +| Option | Description | +|--------|------------------------------------------------| +| out | Specifies the location of the query result. | +| query | Optional selection criteria for documents. | +| sort | Optional sort criteria. | +| limit | Optional maximum number of documents to return| diff --git a/docs/MongoDB/Advanced MongoDB/mongodb-regular-expression.md b/docs/MongoDB/Advanced MongoDB/mongodb-regular-expression.md new file mode 100644 index 000000000..56f2e9bcb --- /dev/null +++ b/docs/MongoDB/Advanced MongoDB/mongodb-regular-expression.md @@ -0,0 +1,65 @@ +--- +id: mongodb-regular-expression +title: MongoDB - Regular Expression +sidebar_label: Regular Expression +sidebar_position: 11 +tags: [mongodb, regular expression, pattern matching] +description: Learn how to use regular expressions for pattern matching in MongoDB using the $regex operator. +--- + +Regular Expressions are commonly used in programming languages to search for patterns or words within strings. MongoDB supports regular expressions for string pattern matching using the $regex operator, based on PCRE (Perl Compatible Regular Expression) syntax. + +## Using Regular Expressions + +Assume we have a document in the `posts` collection: + +```javascript +db.posts.insert({ + "post_text": "enjoy the mongodb articles on tutorialspoint", + "tags": ["mongodb", "tutorialspoint"] +}) +``` + +To search for posts containing the string "tutorialspoint" in their `post_text` field using a regular expression: + +```javascript +db.posts.find({ post_text: { $regex: "tutorialspoint" } }).pretty() +``` + +### Diagram: Regular Expression Query Process + +```mermaid +graph LR; + A[Query Collection] --> B(Regex Pattern Matching); + B --> C(Retrieve Matching Documents); +``` + +### Note: Case Insensitive Search + +To perform a case-insensitive search, use the $options parameter with value "$i" in the regex query: + +```javascript +db.posts.find({ post_text: { $regex: "tutorialspoint", $options: "$i" } }) +``` + +### Using Regex for Array Elements + +Regular expressions can also be applied to array fields, such as searching for posts with tags starting from "tutorial": + +```javascript +db.posts.find({ tags: { $regex: "tutorial" } }) +``` + +### Optimizing Regex Queries + +- Indexed fields improve the performance of regular expression queries by using indexed values for matching. +- Prefix expressions in regular expressions, like "^tut," optimize searches by matching strings starting with specific characters. + +## Table: Regex Search Options + +| Option | Description | +|--------------|----------------------------------------------------------------| +| $regex | Operator for regular expression pattern matching. | +| $options | Optional parameter for regex options like case insensitivity. | +| ^ | Anchor for matching the start of a string. | +| $ | Anchor for matching the end of a string. | diff --git a/docs/MongoDB/Advanced MongoDB/mongodb-text-search.md b/docs/MongoDB/Advanced MongoDB/mongodb-text-search.md new file mode 100644 index 000000000..39dd3636d --- /dev/null +++ b/docs/MongoDB/Advanced MongoDB/mongodb-text-search.md @@ -0,0 +1,86 @@ +--- +id: mongodb-text-search +title: MongoDB - Text Search +sidebar_label: Text Search +sidebar_position: 10 +tags: [mongodb, text search, indexing] +description: Learn how to perform text search in MongoDB using text indexes to search inside string content efficiently. +--- + +Starting from version 2.4, MongoDB supports text indexes for searching inside string content. Text Search uses stemming techniques to search for specified words in string fields by dropping stemming stop words like "a," "an," "the," etc. MongoDB currently supports around 15 languages for text search. + +## Enabling Text Search + +Initially, Text Search was an experimental feature, but starting from version 2.6, it is enabled by default in MongoDB configurations. + +## Creating Text Index + +Consider the following documents in the `posts` collection: + +```javascript +db.posts.insert({ + "post_text": "enjoy the mongodb articles on tutorialspoint", + "tags": ["mongodb", "tutorialspoint"] +}) + +db.posts.insert({ + "post_text": "writing tutorials on mongodb", + "tags": ["mongodb", "tutorial"] +}) +``` + +To create a text index on the `post_text` field, enabling text search inside the posts' text: + +```javascript +db.posts.createIndex({ post_text: "text" }) +``` + +### Using Text Index + +After creating the text index on the `post_text` field, you can search for posts containing specific words using the `$text` operator: + +```javascript +db.posts.find({ $text: { $search: "tutorialspoint" } }).pretty() +``` + +This command retrieves documents that contain the word "tutorialspoint" in their post text. + +### Diagram: Text Search Process + +```mermaid +graph LR; + A[Query Collection] --> B(Text Indexing); + B --> C(Search using $text operator); + C --> D(Retrieve Matching Documents); +``` + +::: note: Performance Considerations + +When using text search in MongoDB: +- Text indexes can significantly improve search performance for string content. +- Consider the language-specific settings for stemming and stop words. +- Optimize text indexes based on the search requirements. +::: +### Table: Text Search Options + +| Option | Description | +|--------|--------------------------------------------------| +| $text | Operator for text search using text indexes. | +| $search| Specifies the search term or phrase. | +| $language| Optional parameter for specifying the language for text search. | + +## Deleting Text Index + +To delete an existing text index, first, find the name of the index using the `getIndexes` method: + +```javascript +db.posts.getIndexes() +``` + +After obtaining the index name, use the `dropIndex` method to delete the text index: + +```javascript +db.posts.dropIndex("post_text_text") +``` + +This command deletes the text index named "post_text_text" from the `posts` collection. diff --git a/docs/MongoDB/Advanced MongoDB/working-with-rockmorgo.md b/docs/MongoDB/Advanced MongoDB/working-with-rockmorgo.md new file mode 100644 index 000000000..3c2124b32 --- /dev/null +++ b/docs/MongoDB/Advanced MongoDB/working-with-rockmorgo.md @@ -0,0 +1,70 @@ +--- +id: working-with-rockmorgo +title: Working with RockMongo +sidebar_label: Working with RockMongo +sidebar_position: 12 +tags: [mongodb, RockMongo, administration, database management] +description: Learn how to work with RockMongo, a MongoDB administration tool, for managing databases, collections, documents, and more. +--- + +RockMongo is a powerful MongoDB administration tool that provides a user-friendly interface for managing MongoDB databases, collections, documents, and indexes. It is similar to PHPMyAdmin for PHP and MySQL. + +## Downloading and Installing RockMongo + +You can download the latest version of RockMongo from the [official GitHub repository](https://github.com/iwind/rockmongo). After downloading, follow these steps to install RockMongo: + +1. Unzip the downloaded package into your server's root folder. +2. Rename the extracted folder to "rockmongo." +3. Access RockMongo by opening any web browser and navigating to the `index.php` page in the `rockmongo` folder. +4. Log in using the default credentials: Username - admin, Password - admin. + +### Diagram: RockMongo Installation Process + +```mermaid +graph LR; + A[Download RockMongo] --> B(Unzip Package); + B --> C(Rename Folder to RockMongo); + C --> D(Access index.php in Browser); + D --> E(Login with Default Credentials); +``` + +:::note Default Credentials + +Upon installation, RockMongo uses default credentials (Username: admin, Password: admin). Change these credentials for security purposes. + +::: +## Basic Operations with RockMongo + +Let's explore some basic operations you can perform with RockMongo: + +### Creating New Database + +1. Click on the "Databases" tab. +2. Click "Create New Database." +3. Enter the new database name and click "Create." + +### Creating New Collection + +1. Select the desired database from the left panel. +2. Click "New Collection" at the top. +3. Provide the collection name and click "Create." + +### Creating New Document + +1. Navigate to the collection where you want to add documents. +2. Click "Insert" at the top. +3. Enter the document's data in JSON or array format and click "Save." + +### Export/Import Data + +1. Select a collection. +2. Click "Export/Import" at the top to export or import data in zip format. + +## Table: RockMongo Operations Overview + +| Operation | Description | +|---------------------|---------------------------------------------------------| +| Create New Database | Add a new database to the MongoDB server. | +| Create New Collection| Create a new collection within a database. | +| Create New Document | Add a new document to a collection. | +| Export/Import Data | Transfer data in and out of collections in zip format. | diff --git a/docs/PHP/_category.json b/docs/PHP/_category.json new file mode 100644 index 000000000..96edcfab0 --- /dev/null +++ b/docs/PHP/_category.json @@ -0,0 +1,8 @@ +{ + "label": "PHP", + "position": 13, + "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 new file mode 100644 index 000000000..0dbb47213 --- /dev/null +++ b/docs/PHP/home.md @@ -0,0 +1,84 @@ +--- +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-features.md b/docs/PHP/php-features.md new file mode 100644 index 000000000..997aaad84 --- /dev/null +++ b/docs/PHP/php-features.md @@ -0,0 +1,67 @@ +--- +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 new file mode 100644 index 000000000..ff980dd8a --- /dev/null +++ b/docs/PHP/php-hello-world.md @@ -0,0 +1,78 @@ +--- +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 new file mode 100644 index 000000000..dd5f20668 --- /dev/null +++ b/docs/PHP/php-history.md @@ -0,0 +1,65 @@ +--- +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 new file mode 100644 index 000000000..dffa853ea --- /dev/null +++ b/docs/PHP/php-installation.md @@ -0,0 +1,62 @@ +--- +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-introduction.md b/docs/PHP/php-introduction.md new file mode 100644 index 000000000..b7688e969 --- /dev/null +++ b/docs/PHP/php-introduction.md @@ -0,0 +1,45 @@ +--- +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-syntax.md b/docs/PHP/php-syntax.md new file mode 100644 index 000000000..e06ac04ea --- /dev/null +++ b/docs/PHP/php-syntax.md @@ -0,0 +1,103 @@ +--- +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