Home > Backend Development > PHP Tutorial > PHP converts a string from one character to another function convert_cyr_string()

PHP converts a string from one character to another function convert_cyr_string()

黄舟
Release: 2023-03-16 21:46:01
Original
1441 people have browsed it

Example

Convert a string from one character set to another:

<?php
$str = "Hello world! æøå";
echo $str . "<br>";
echo convert_cyr_string($str,&#39;w&#39;,&#39;a&#39;);
?>
Copy after login

Definition and usage

convert_cyr_string() function converts a string from one Cyrillic character set to another.

The supported Cyrillic character sets are:

k - koi8-r

w - windows-1251

i - iso8859-5

a - x-cp866

d - x-cp866

m - x-mac-cyrillic

Note: This function is binarysafeof.

Syntax

convert_cyr_string(string,from,to)
Copy after login

Parameters Description

string Required. Specifies the string to be converted. ​

from ​ Required. A character that specifies the source Cyrillic character set. ​

to ​ Required. A character specifying the target Cyrillic character set.

Technical details

Return value: Returns the converted string.

PHP version: 4+

convert_cyr_string example

XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don&#39;t forget the meeting!</body>
</note>
Copy after login

PHP code:

<?php
$xml = simplexml_load_file("test.xml");

foreach ($xml->children() as $child)
  {
  echo "Child node: " . $child;
  }
?>
Copy after login

The output is similar to:

Child node: George
Child node: John
Child node: Reminder
Child node: Don&#39;t forget the meeting!
Copy after login

The above is the detailed content of PHP converts a string from one character to another function convert_cyr_string(). For more information, please follow other related articles on the PHP Chinese website!

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