sql substr code example

Example 1: php limit string length

if (strlen($str) > 10)
   $str = substr($str, 0, 7) . '...';

Example 2: take 10 character from string using php

$return_string = substr("Hi i am returning first 10 characters.", 0, 10);
Output:
"Hi i am re"

Example 3: substr() javascript

const str = 'substr';

console.log(str.substr(1, 2)); // (1, 2): ub
console.log(str.substr(1)); // (1): ubstr

/* Percorrendo de trás para frente */
console.log(str.substr(-3, 2)); // (-3, 2): st
console.log(str.substr(-3)); // (-3): str

Example 4: javascript substring

// zero-based index, 'end' is excluded from result
myString.substring( start, end )

Example 5: substr

str.substr(start[, length])

Tags:

Sql Example