Blog Archives

String StartsWith and EndsWith in JavaScript

The following are a simple implementation checking whether a string starts with a prefix or ends with a suffix in JavaScript. Here we use indexOf() method of JavaScript String object. Syntax: string.indexOf(search, start) Parameters: search is the string to search

Tagged with: , ,
Posted in JavaScript

String StartsWith and EndsWith in PHP

The following are a simple implementation checking whether a string starts or ends with another string in PHP. Note that we need triple equals sign (===) since strpos() may return FALSE, while FALSE == 0 is actually TRUE. The above

Tagged with: , , , , ,
Posted in PHP