Home > Backend Development > PHP Tutorial > 问个unicode编码的问题

问个unicode编码的问题

WBOY
Release: 2016-06-23 14:12:11
Original
794 people have browsed it

js里有个函数String.charCodeAt可以把一个字符串指定位置的字符转换成unicode编码,返回一个数字。现在我想把一个网址例如http://bbs.csdn.net/作为一个字符串整体转换成unicode编码,我想用php的函数实现,请问有类似这个js函数功能的php函数么?在网上找了半天发现都是汉字转unicode编码的,我想要的只是一个英文和符号字符转换的即可!


回复讨论(解决方案)

只针对基本 ASCII 字符而言,只需使用 ord 函数即可
如果包含汉字,那么可用 iconv 函数转码,目标字符集为 UCS-2
不过需要注意的是:在 UCS-2 字符集中,基本 ASCII 字符也是 2 字节的

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template