String Functions in PHP: PART 2

Introduction

In this article I describe the PHP string functions chop, chr and chunk_split . To learn some other math functions, go to:

1 String Functions in PHP: Part1

PHP chop() Function

The PHP string chop function will remove a white space or other predefined character from the right end of a string.

Syntax

chop( string, charlist)

Parameter in chop Function

The parameters of the chop function are:

Parameter Description
string It specifies the string to check.
charlist It specifies when you want, which character is removed from the string.

Example

An example of the chop
function is:

<?
php
$
str = "Welcome at MCN Solution!\n\n";
echo
$str;
echo
chop($str);
?>


Output

chop-string-function-php.jpg

PHP chr() Function

The PHP string chr function returns a specific character.

Syntax

chr( ascii)

Parameter in chr Function

The parameter of the chr function is:

Parameter Description
ascii It specifies an ASCII value.

Example

An example of the chr
function is:

<?php

echo chr(45)."<br />";

echo chr(076)."<br />";

echo chr(0x45)."<br />";

?>

Output

chr-string-function-in-php.jpg

PHP chunk_split function

The PHP chunk_split function splits a string into smaller chunks and returns the string chunks.

Syntax
 

chunk(string, length, end)

Parameter in chunk_split  Function

The parameters of the chunk_split function are:

Parameter Description
string It specifies the string to split.
length It specifies a number that defines the length of the chunks, and the default is 76.
end It specifies line ending sequence.

Example

An example of the
chunk_split  function is:
<?
php
$
str = "Welcome at MCN  Solution!";
echo
chunk_split($str,8,"...");
?>

Output

chunk-split-string-function-in-php.jpg


Similar Articles