There is no direct function for this in my knowledge. But it can be done easily like so. “`php if ( mb_strlen( $string, ‘ASCII’ ) === mb_strlen( $string, ‘utf-8’ ) ) { return true; } “`
Category: Coding
How to disable translation pop-up on website in Google Chrome
Google Chrome on Android tries to show pages in user’s preferred language by continuously showing translation pop-up on each page load. This happens when website content is in a different language than user’s preferred language. But this creates issues in user experience by hiding bottom content on website. My site had fixed bottom navigation bar…
Restrict number of selected checkboxes in html
This code will restrict html multi select input to given number. document.addEventListener( “click”, function( event ) { if ( event.target.matches( ‘.input-checkbox’ ) ) { var inputCheckboxes = document.querySelectorAll( ‘.input-checkbox[type=”checkbox”]:checked’ ); if( inputCheckboxes.length > 3 ) { event.preventDefault(); alert( ‘You cannot select more than 3 categories for a post.’ ); } } } );
MySQL Disk Size Issue
I was facing a strange issue on one of my servers. Storage was getting full even when I did not upload any extra files. Turned out it was a MySQL logging issue and got resolved only when I disabled logging. References: https://www.christophe-casalegno.com/mysql-how-to-purge-binary-logs-when-you-have-no-space-left-on-device/ https://www.alittleofboth.com/2020/04/droplet-out-of-disk-space/ https://www.digitalocean.com/community/questions/where-did-my-disc-space-go
Why click event not working on SVG
I created a simple menu with SVG icons and to my surprise, clicking on the icon was not taking me to the linked url. It turned out that as SVGs are independent HTML objects, the target element is actually nested path. So, it does not match with the clicked element and thus click event listeners…
Add event listener on SVG element
I was facing problem while adding event listener to an svg element. Then I added event listeners to both svg and path tags, and it worked.
Resolved: TWA App not working fullscreen when downloaded from Play Store
To hide the address bar in a TWA app, you must have setup and asset links file on our server with valid SHA certificate fingerprint. Sometimes the app works fine when we test it by directly installing through apk, but address bar is shown when we download the app from play store. The reason for…
How to track if a web page is opened in TWA app
The Trusted Web Activity (TWA) in Chrome has made it so easy to package and publish any website as an app. But the problem arises when we want to track when your website was opened inside the TWA app. Usually we can easily do this in a webview app by appending a custom string to…
How to persist state through query string in url
In some cases when you do not have the option of cookies to manage state, query string can be a good option. In this article, I am going to use some Javascript to persist state through a query string in the url. The Javascript code is added to head section of html when the desired…
Modify page title tag in WordPress
To change page title tag in WordPress, use the pre_get_document_title filter. Most of the answers on web have mentioned the filter wp_title, but do not use it as wp_title function will be deprecated in future and wp_title hook will not work. At present, wp_title filter does not work when modifying the title tag.
Prevent Form Resubmission on Page Refresh
We face a common issue on many websites that whenever a form submits to the same page, and then we refresh the page, the form data is submitted again. Sometimes the browser asks for confirmation, sometimes it does not. It becomes really frustrating if it causes an operation to happen twice. To prevent this on…
Make Javascript sequential with “async” and “await”
Javascript code can be easily made sequential with the help of two simple, yet very powerful keywords “async” and “await”.
Javascript: Loop over querySelectorAll without error
In Javascript, there are a lot of instances when you want to find multiple elements on a page to apply a common operation to all of them. Suppose you want to hide elements of a particular class present on your web page. To do this, first get an array of all such elements using querySelectorAll…
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…