There is no direct function for this in my knowledge. But it can be done easily like so. if ( mb_strlen( $string, ‘ASCII’ ) === mb_strlen( $string, ‘utf-8’ ) ) { return true; }
Tag: PHP
Prevent Memory Leak in WordPress
Recently I faced an issue of memory leak in one of my WordPress projects. I was running a function that was reading post meta and user metadata of thousands of objects. I thought reading data from MySQL is cheap in terms of processing power and memory, but it turned out it was causing my function…
How to change Post Type in WordPress
Use these simple methods to easily change post type of single or multiple posts while working with multiple post types in WordPress.
How to view and modify WordPress rewrite rules
Sometimes a page load issue in your WordPress website has more to do with some random error rather than a bug in your code. In this case, it was rewrite rules cache.
How to count words in Unicode string using PHP
How to count words in Unicode string using PHP? This sounds too easy. After all, PHP has so many string manipulation functions. To count words, we can simply use str_word_count and we are good to go. But there is a problem. While this function works fine for English strings, developers find this function unpredictable as sometimes…