Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 1003 of 2109
PHP – How to return character by Unicode code point value using mb_chr()?
In PHP, the mb_chr() function is used to return a character by Unicode code point value. This function returns a string containing the character identified by the Unicode code point value, encoded in the specified encoding. Syntax string mb_chr(int $codepoint, string $encoding) Parameters mb_chr() accepts two parameters: $codepoint and $encoding. $codepoint − The Unicode code point value to convert. For example, 128024 for U+1F418 ELEPHANT. $encoding − The character encoding. If omitted or null, the internal character encoding value will be used. ...
Read MorePHP – Check if strings are valid for the specified encoding using mb_check_encoding()
In PHP, the mb_check_encoding() function is used to check if the given strings are valid for the specified encoding. This function validates whether the specified byte stream conforms to the stated encoding rules. Syntax bool mb_check_encoding(string $value = null, string $encoding = null) Parameters mb_check_encoding() accepts two parameters: $value − The byte stream, string, or array to check. If omitted, it checks all input from the beginning of the request. $encoding − The expected encoding. If omitted, it uses the internal encoding. Return Value mb_check_encoding() returns true if the ...
Read MorePrint contents of a file in C
In C, printing the contents of a file involves opening the file, reading its data character by character or line by line, and displaying it on the console. The fopen(), fgetc(), and fclose() functions are commonly used for this purpose. Syntax FILE *fopen(const char *filename, const char *mode); int fgetc(FILE *stream); int fclose(FILE *stream); Method 1: Reading Character by Character Let's say we have "new.txt" file with the following content − 0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demo Note: Create a file named "new.txt" in your working directory ...
Read MorePHP – Convert a string to a requested character encoding using iconv()
In PHP, the iconv() function is used to convert a string from one character encoding to another. It performs character set conversion on the string from a source encoding to a target encoding, making it essential for handling multilingual text and ensuring proper character display across different systems. Syntax string iconv(string $from_encoding, string $to_encoding, string $string) Parameters The iconv() function accepts three parameters: $from_encoding − The input charset (source encoding) $to_encoding − The output charset (target encoding). You can append //TRANSLIT or //IGNORE for special handling $string − The string to be ...
Read MoreEOF, getc() and feof() in C
In C programming, EOF (End of File), getc(), and feof() are essential for file handling operations. EOF is a constant that indicates the end of a file stream, while getc() reads characters from files and feof() checks if the end-of-file indicator has been set. EOF (End of File) EOF stands for End of File and is a macro defined in . The getc() function returns EOF when it reaches the end of file or encounters an error. Syntax #define EOF (-1) Example: Using EOF with getc() Note: This example assumes a ...
Read MorePHP – How to cut out part of a string using iconv_substr()?
In PHP, the iconv_substr() function is used to cut out a portion of a string based on character position, with proper support for multibyte character encodings like UTF-8. This function is particularly useful when working with international text that may contain special characters. Syntax string iconv_substr(string $string, int $offset, ?int $length = null, ?string $encoding = null) Parameters $string − The original string to extract from $offset − Starting position (0-based). If negative, counts from the end of the string $length − Number of characters to extract. If omitted, extracts to the end ...
Read Morefseek() vs rewind() in C
In C, both fseek() and rewind() are used to change the position of the file pointer, but they serve different purposes. fseek() provides flexible positioning anywhere in the file, while rewind() specifically moves the pointer back to the beginning. fseek() Function The fseek() function moves the file pointer to a specific position based on an offset and reference point. Syntax int fseek(FILE *stream, long int offset, int whence) Here are the parameters − stream − Pointer to the FILE object offset − Number of bytes to move from the reference position ...
Read MorePHP – Find the last occurrence of a needle within a haystack using the iconv_strrpos() function
In PHP, the iconv_strrpos() function is used to find the last occurrence of a needle within a haystack. This function returns the character position of the last match in a string, supporting various character encodings. Syntax iconv_strrpos(string $haystack, string $needle, ?string $encoding = null): int|false Parameters iconv_strrpos() accepts three parameters: $haystack, $needle and $encoding. $haystack − The whole string to search within. $needle − The substring to search for in the haystack. $encoding − The character encoding. If omitted or null, uses iconv.internal_encoding. Return Values iconv_strrpos() returns the numeric ...
Read Morecalloc() versus malloc() in C
In C, both malloc() and calloc() are used for dynamic memory allocation, but they have important differences in initialization and usage. Understanding when to use each function is crucial for effective memory management. Syntax void *malloc(size_t size); void *calloc(size_t number, size_t size); malloc() Function The malloc() function allocates a block of memory of the specified size in bytes. It does not initialize the allocated memory, leaving it with garbage values. Parameters size − Size of memory block to allocate in bytes Example #include #include ...
Read MorePHP – How to return the character count of a string using iconv_strlen()?
In PHP, the iconv_strlen() function is used to return the character count of a given string. This function is particularly useful for multibyte character encodings where regular strlen() might give incorrect results. It was introduced in PHP 5 and the encoding parameter became nullable from PHP 8.0. Syntax int|false iconv_strlen(string $string, ?string $encoding = null) Parameters This function accepts two parameters: $string − The input string to count characters from. $encoding − The character encoding to use. If omitted or null, the value of iconv.internal_encoding configuration option is used. Return ...
Read More