search
HomeBackend DevelopmentPHP ProblemHow to convert string in php ascii

How to convert string in php ascii

Sep 12, 2020 am 09:29 AM
asciiphp

You can use the chr function in PHP to convert the ascii code value into a string. The syntax of this function is "string chr (int ascii);" and its parameter "ascii" represents the ascii value that needs to be converted. .

How to convert string in php ascii

Recommended: "PHP Video Tutorial"

Use PHP's chr and ord functions to implement strings Convert to and from ASCII codes

chr and ord functions are used to convert strings to ASCII codes.

ASCII codes are the encoding of characters that can be displayed by the computer. The value range is 0-255, including punctuation, letters, numbers, Chinese characters, etc. During the programming process, specified characters are often converted into ASCII codes for comparison.

The following is the function provided by PHP to convert ASCII codes and characters.

1. chr() function

This function is used to convert ASCII code value into a string. Its function declaration is as follows:

string chr (int ascii);

2. ord() function

This function is used to convert a string into an ASCII code value. The function declaration is as follows:

int ord(string str);

Example:

Use the chr() function and ord() function to convert between strings and ASCII codes. The program code is as follows:

<?php 
$str1=chr(88); 
echo $str1; //返回值为X 
echo "\t"; 
$str2=ord(&#39;S&#39;); 
echo $str2; //返回值为83 
?>

Run result: X 83

The above is the detailed content of How to convert string in php ascii. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor