Home » PHP

PHP ord() Function with Example

PHP ord() function: Here, we are going to learn about the ord() function with Example in PHP.
Submitted by IncludeHelp, on February 05, 2019

PHP ord() function

ord() function is a string function, it is used to get the ASCII code of the first character of the given string.

Syntax:

    ord(string);

It accepts 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 





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.