Download the PHP package mojahed/mparser without Composer
On this page you can find all versions of the php package mojahed/mparser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mojahed/mparser
More information about mojahed/mparser
Files in mojahed/mparser
Package mparser
Short Description MParser is a powerful PHP package that simplifies parsing complex strings with custom tokens and expressions. With a flexible trait-based architecture, it enables effortless creation and extension of parsing functionality. Easily integrate MParser into your projects for efficient string processing and data extraction in a user-friendly manner.
License MIT
Informations about the package mparser
MParser - Powerful String Parsing Library
MParser is a PHP package that simplifies parsing complex strings with custom tokens and expressions. It allows you to effortlessly create and extend parsing functionality using a flexible trait-based architecture. Easily integrate MParser into your projects for efficient string processing and data extraction in a user-friendly manner.
Installation
You can install the MParser package using Composer. Run the following command:
Basic Usage
To use MParser, follow these steps:
-
Import the necessary class:
use Mojahed\MParser;
- Parse the string with the provided data:
Available Methods
MParser provides the following methods for parsing and replacing tokens in the input string:
exp
Splits the token and returns the value at the specified index.
Example:
!Note : exp doesn't supports (,) comma as first parameter
cut
Extracts a substring from the token based on the start and length specified.
Example:
cut_back
Extracts a substring from the end of the token based on the length specified.
Example:
reverse
Reverses the characters of the token.
Example:
sum
Adds the specified number to the token (assumed to be numeric).
Example:
sub
Subtracts the specified number from the token (assumed to be numeric).
Example:
mul
Multiplies the token with the specified number (assumed to be numeric).
Example:
div
Divides the token by the specified number (assumed to be numeric). Returns 0 if the divisor is zero.
Example:
power
Raises the token to the power of the specified number (assumed to be numeric).
Example:
upper
Converts the token to uppercase.
Example:
lower
Converts the token to lowercase.
Example:
capitalize
Capitalizes the first character of the token while converting the rest to lowercase.
Example:
replace
Replaces occurrences of the search string with the replacement string in the token.
Example:
length
Returns the length of the token (number of characters).
Example:
concat
Concatenates the token with the specified string.
Example:
Multiple Expression
Use multiple expression at a time.
Example:
Custom Methods
You can add your own custom methods to extend the functionality of MParser. Simply create a new class that inherits from MParser
and define your custom methods. For example:
By creating the ChildParser
class and defining the _reverse
method, you can now use [reverse()]
in your input string to call the custom method.
Contributing
If you find any issues, have suggestions, or want to add new features, feel free to create an issue or submit a pull request on GitHub.
License
This package is open-source and available under the MIT License. Feel free to use and modify it according to your needs.