Jump to: navigation, search

Php substr

From w3cyberlearnings

Contents

PHP function substr

This function returns part of a given string.

Syntax substr

  • string: string input
  • start: positive number(start from the right direction-->), negative number (start from the left direction <--), 0 (start at the first character in a spring)
  • length: positive number (the length to be returned from the start), negative number (the length will be returned from the end of the string)
substr(string, start, length);

Example 1

<?php
echo substr("Hello World",6);
?>

Output

World

Example 2

<?php
echo substr("I go to fish with you",-9);
?>

Output

with you

Example 3

<?php
echo substr("Great to know you",0,-3);
?>

Output

Great to know

Example 4

<?php
echo substr("Great to know you",-3,3);
?>

Output

you

Example 5

<?php
echo substr("Great to know you",5,-3);
?>

Output

to know

Related Functions


Navigation
Web
SQL
MISC
References