PHP hacken()

PHPz
Freigeben: 2024-08-29 12:52:50
Original
201 Leute haben es durchsucht

If there are any whitespaces or any other characters that are predefined in a string, a function called chop() function can be used to remove them from the right side of the string which is also an alias for a function called rtrim() function in PHP. This function is supported in the fourth version and the above versions after fourth version of PHP and the return value of this function in PHP is string but is a changed string when compared to the input string passed to the function.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax

The syntax to declare chop() function in PHP is as follows:

chop(string_name, char_list)
Nach dem Login kopieren

where,

  • string_name: Is the name of the string that requires trimming, that is the chop() function must be applied on. This is the essential parameter of the syntax and is mandatory. The data type of this parameter is string data type.
  • char_list: It specifies the list of characters to be removed from the string that is passed as a parameter. If the char_list parameter is not specified in the chop() function that is being called, the chop() function will be applied on the following list of characters like an ordinary space, \0” which is also called as Null byte, \t” which is also called as a tab, \n” which is also called as line feed, \x0B” which is also called as a vertical tab, “\r” which is also called as a carriage return. This is not an essential parameter of the syntax and is optional. The data type of this parameter is string data type.

How does chop() Function work in PHP?

Chop() function is one of the string functions in PHP. The required whitespaces or specified characters or string from the right side of the string can be removed using chop() function in PHP.

Consider the below program:

Code:

<?php
//declaring the string Shobha.Shivakumar#
$string = "Shobha.Shivakumar#";
//Using chop() function to remove the character # from the right side of the string
echo (chop($string, "#")."\n");
//Using chop() function to remove the characters akumar# from the right side of the string
echo (chop($string, "akumar#")."\n");
//Using chop() function to remove the characters .Shivakumar# from the right side of the string
echo (chop($string, "ha.Shivakumar#")."\n");
?>
Nach dem Login kopieren

Output:

PHP hacken()

Explanation:

  • In the above program, a string is declared upon which the chop() function in PHP must be applied. The string declared in the above program is Shobha.Shivakumar#. By using chop() function in PHP, we can remove the whitespaces or the specific characters from the right side of the string. In our program, we apply the chop function on the string to remove the # character from the string Shobha.Shivakumar#.
  • An echo statement in PHP is used to print the changed string after the application of the chop() function on the given string. Echo (chop($string, “#”).”\n”); statement is used in PHP to perform this operation and the output of this is Shobha.Shivakumar which can be seen in the snapshot. We then apply the chop function on the string to remove the akumar# characters from the string Shobha.Shivakumar#. An echo statement in PHP is used to print the changed string after the application of the chop() function on the given string. echo (chop($string, “akumar#”).”\n”); statement is used in PHP to perform this operation and the output of this is Shobha.Shiv which can be seen in the snapshot.
  • We then apply the chop function on the string to remove the ha.Shivakumar# characters from the string Shobha.Shivakumar#. An echo statement in PHP is used to print the changed string after the application of the chop() function on the given string. echo (chop($string, “Shivakumar#”).”\n”); statement is used in PHP to perform this operation and the output of this is Shob which can be seen in the snapshot. “\n” is used in every echo statement in PHP to print the output of each line in a new line. The same operation can be performed on different character on different types of strings.

Examples of PHP chop()

Given below are the examples:

Example #1

PHP program to illustrate the working of chop() function on strings.

Code:

<?php
//declaring the string Shobha.Shivakumar!
$string= "Shobha.Shivakumar!";
//printing the string on which the chop() function will be applied and making sure the next statement will be printed in a new line
echo $string. "\n";
//printing the changes string after the application of the input string
echo chop($string, "r!");
?>
Nach dem Login kopieren

Output:

PHP hacken()

Explanation:

  • In the above program, a string is declared upon which the chop() function in PHP must be applied. The string declared in the above program is Shobha.Shivakumar!. By using chop() function in PHP, we can remove the whitespaces or the specific characters from the right side of the string. In our program, we apply the chop function on the string to remove the characters r! from the string Shobha.Shivakumar!
  • An echo statement in PHP is used to print the changed string after the application of the chop() function on the given string. echo (chop($string, “r!”); statement is used in PHP to perform this operation and the output of this is Shobha.Shivakuma which can be seen in the snapshot. “\n” is used in the second echo statement in PHP to sure the next statement will be printed in a new line. The same operation can be performed on different character on different types of strings.

Example #2

PHP program to illustrate the working of chop() function on strings.

Code:

<?php
//declaring the string Hello! followed by Shobha Shivakumar in a new line, the string is followed by two new line characters
$string= "Hello! \n Shobha Shivakumar \n \n";
//the string is printed
echo $string;
//chop() function is applied on the string without specifying any parameter
echo chop($string);
//The changed string is printed
echo $string;
?>
Nach dem Login kopieren

Output:

PHP hacken()

Explanation:

  • In the above program, a string is declared upon which the chop() function in PHP must be applied. The string declared in the above program is Hello! \n Shobha Shivakumar \n \n. By using chop() function in PHP, we can remove the whitespaces or the specific characters from the right side of the string. In our program, we apply the chop function on the string without specifying any parameters.
  • An echo statement in PHP is used to print the changed string after the application of the chop() function on the given string. echo $string; statement is used in PHP to perform this operation and the output of this is Hello! Followed by Shobha Shivakumar in a new line and two new line spaces after that can be seen in the snapshot. “\n” is used in the echo statement in PHP to sure the next statement will be printed in a new line. The output after the application of chop() function without specifying the parameters removes the two line characters from the right side of the string.

Das obige ist der detaillierte Inhalt vonPHP hacken(). Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Verwandte Etiketten:
php
Quelle:php
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!