Answers for "str sub php"

PHP
49

substr() php

<?php
echo substr('abcdef', 1);     // bcdef
echo substr('abcdef', 1, 3);  // bcd
echo substr('abcdef', 0, 4);  // abcd
echo substr('abcdef', 0, 8);  // abcdef
echo substr('abcdef', -1, 1); // f

// Accessing single characters in a string
// can also be achieved using "square brackets"
$string = 'abcdef';
echo $string[0];                 // a
echo $string[3];                 // d
echo $string[strlen($string)-1]; // f

?>

//substr() function returns certain bits of a string
Posted by: Guest on February-20-2020
5

subtract string php

//if you know what stirng you want to subtact then use
// str_replace($search, $replace, $subject)
$x =  "Hi, I am uzair and I am a php dev.";
echo str_replace("and I am a php dev.", "",$x);

/**
or
if you don't know and what to subtract just last two characters or 
5 ch at the begning etc then use substr()
**/ 
  
$rest = substr("abcdef", -1);    // returns "f"
$rest = substr("abcdef", -2);    // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
Posted by: Guest on April-03-2022
0

php substr

<?php
$rest = substr("abcdef", -1);    // returns "f"
$rest = substr("abcdef", -2);    // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
?>
Posted by: Guest on February-01-2022

Browse Popular Code Answers by Language