

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP – Convert a string to a requested character encoding using iconv()
In PHP, the iconv() function is used to convert a string to the requested character encoding. It is used to perform a character set conversion on the string "string" from from_encoding to to_encoding.
Syntax
string iconv(str $from_encoding, str $to_encoding, str $string)
Parameters
The iconv() function accepts three parameters: $from_encoding, $to_encoding and $string.
$from_encoding− This parameter is used to specify the input charset.
$to_encoding− This parameter is used for the output charset.
$string− This parameter is used to convert the string.
Return Values
iconv() returns the converted string on success or it returns False on failure.
Example
<pre> <?php // used the Dollar symbol to convert in string $text = "the Dollar symbol '$'"; echo 'Original:', $text, PHP_EOL; echo 'TRANSLIT: ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL; echo 'IGNORE: ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL; ?> </pre>
Output
Original:the Dollar symbol '$' TRANSLIT: the Dollar symbol '$' IGNORE: the Dollar symbol '$'
Example 2
<pre> <?php // used the Dollar symbol to convert in string $string = "Indian Rupees '?'"; echo 'Original: ', $string, PHP_EOL; echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1", $string), PHP_EOL; echo 'IGNORE: ', iconv("UTF-8", "ISO-8859-1", $string), PHP_EOL; ?> </pre>
Output
Original: Indian Rupees '?' TRANSLIT: Indian Rupees '?' IGNORE: Indian Rupees '?'
- Related Questions & Answers
- PHP – How to detect character encoding using mb_detect_encoding()
- PHP – How to set the character encoding detection order using mb_detect_order()?
- PHP – Detect HTTP input character encoding with mb_http_input()
- PHP – Set the current setting for character encoding conversion using iconv_set_encoding() function
- Node.js – Retrieving file character encoding
- PHP – Get aliases of a known encoding type using mb_encoding_aliases()
- PHP – How to return the character count of a string using iconv_strlen()?
- PHP – Retrieve internal configuration variables of iconv extension using iconv_get_encoding() function
- PHP – Get or set the HTTP output character encoding with mb_http_output()
- Convert ASCII TO UTF-8 Encoding in PHP?
- PHP – Case folding in a string using mb_convert_case()
- PHP – Make a lower case string using mb_strtolower()
- Encoding string based on character frequency in JavaScript
- Java program to convert a character array to string
- PHP 8 – Using str_contains() to check if a string contains a substring
Advertisements