String Functions in PHP: Part 11

Introduction

In this article I describe the PHP string functions number_format, ord and parse_str. To learn some other math functions, go to:

  1. String Functions in PHP: Part1
     
  2. String Functions in PHP:Part2
     
  3. String Functions in PHP:Part3
     
  4. String Functions in PHP:Part4
     
  5. String Functions in PHP:Part5
     
  6. String Functions in PHP:Part6
     
  7. String Functions in PHP:Part7
     
  8. String Functions in PHP:Part8
     
  9. String Functions in PHP:Part9
     
  10. String Functions in PHP:Part10

PHP number_format() Function

The PHP number_format function is used to set the format of numeric output.

Syntax

number_format (number,decimals,decimalpoint, separator)

Parameter in number_format Function

The parameters of the money_format function are:

Parameter Description
number It specifies the number to be formatted.
decimals It sets the number of decimal points.
decimalpoint It specifies what string is used for the decimal point.
separator It sets the thousands separator.

Example

An example of the
number_format function is: 

<?php

echo number_format("999999");

echo "<br />";

echo number_format("999999",2);

echo "<br />";

echo number_format("1000000",2,",",".");

?>

Output

number-format-function-in-php.jpg


PHP ord() Function

The PHP ord function returns the ASCII value of the first character of a string.

Syntax

ord(string)

Parameter in ord Function

The parameter of the ord function is:

Parameter Description
string It specifies a string to get the ASCII value from

Example

An example of the
money_format function is: 

<?php

echo ord("M")."</br>";

echo ord("MCN");

?>


Output

ord-string-function-in-php.jpg

PHP parse_str() Function

The PHP parse_str function parses the string into a variable.

Syntax

parse_str(string,array)

Parameter in parse_str Function

The parameters of the parse_str function are:

Parameter Description
string It specifies input string.
array It specifies the name of the array to store the variable.

Example

An example of the parse_str
function is: 

<?php
parse_str
("Rank=1&compname=Mcn%20Solution",$ArrayVal);
echo
"<pre>";
print_r
($ArrayVal);
?>
   

Output

parse-str-function-in-php.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all