PHP ord() Function with Example

PHP ord() work: Here, we will find out about the ord() work with Example in PHP.

PHP ord() work

ord() work is a string capacity, it is utilized to get the ASCII code of the main character of the given string.

Syntax:

    ord(string);
  • It acknowledges the string and returns the number value (ASCII code).

Examples:

    Input: "Abc"
    Output: 65

PHP Code:

<?php
	$str = "Abc";
	echo ("ASCII code of first character is = " . ord($str) . "\n");

	$str = "Hello world";
	echo ("ASCII code of first character is = " . ord($str) . "\n");	

	$str = "_okay";
	echo ("ASCII code of first character is = " . ord($str) . "\n");	

	$str = "123Hello";
	echo ("ASCII code of first character is = " . ord($str) . "\n");	
?>

Output

ASCII code of first character is = 65 
ASCII code of first character is = 72 
ASCII code of first character is = 95 
ASCII code of first character is = 49

2 thoughts on “PHP ord() Function with Example”

  1. Pingback: PHP program to convert string to uppercase without using the library function – JustTechReview
  2. Pingback: PHP program to convert string to lowercase without using the library function – JustTechReview

Leave a Comment

error: Alert: Content is protected!!