Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get last character of string php

substr("testers", -1); // returns "s"
Comment

get last characters of string in php

<?php
	echo substr('Telangana', -3); // ana
	print "<br/>";
	echo substr('Telangana', -1, 1); // a
	print "<br/>";
	echo substr('Telangana', 0, -1); // Telangan
?>
Comment

get last word from string php

function getLastWord($string)
    {
        $string = explode(' ', $string);
        $last_word = array_pop($string);
        return $last_word;
    }
Comment

get last letter in php

substr("testers", -1); // returns "s"
//Or, for multibyte strings :
mb_substr("multibyte string…", -1); // returns "…"
Comment

Get the Last Character of a String in PHP

phpCopy<?php  
$string = 'This is a string';
$lastChar = substr($string, -1);
echo "The last char of the string is $lastChar.";
?>
Comment

php extract last n words of string

<?php

$str = "NAME WITH SPACES FIELD1 FIELD2 FIELD3 FIELD4";

preg_match("/(S+)s(S+)s(S+)s(S+)$/", $str, $matches);

var_dump($matches);

/* array(5) {
  [0] => string(27) "FIELD1 FIELD2 FIELD3 FIELD4"
  [1] => string(6) "FIELD1"
  [2] => string(6) "FIELD2"
  [3] => string(6) "FIELD3"
  [4] => string(6) "FIELD4"
} */
Comment

Get the Last Character of a String in PHP

phpCopy<?php  
$string = "This is a string";

$lastChar = $string[-1];
echo "The last char of the string is $lastChar.";
?>
Comment

get last word of string php

$split = explode(" ", $string);

echo $split[count($split)-1];
Comment

Get the Last Character of a String in PHP

phpCopy<?php 
$string = "This is a string";
$lastCharPosition = strlen($string) - 1;  
for ($x = $lastCharPosition; $x < strlen($string); $x++) {
    $newString = $string[$x]; 
} 
echo "The last char of the string is $newString.";
?> 
Comment

Get the Last Character of a String in PHP

phpCopy<?php  
$string = "This is a string";
$lengthOfString = strlen($string);
$lastCharPosition = $lengthOfString-1;
$lastChar = $string[$lastCharPosition];
echo "The last char of the string is $lastChar.";
?>
Comment

get last word of string php

$split = explode(" ", $string);

echo $split[count($split)-1];
Comment

Get the Last Character of a String in PHP

phpCopysubstr($stringName, $startingPosition, $lengthOfSubstring);
Comment

PREVIOUS NEXT
Code Example
Php :: php show active page 
Php :: php declare strict_types 
Php :: target class usercontroller does not exist. in laravel 8 
Php :: how to build jquery messages notification with php and mysq 
Php :: php get tempfile 
Php :: parameterized function in php 
Php :: create migration, controller, model and seeder laravel 
Php :: php check if input is int 
Php :: eloquent limit vs take 
Php :: hmtl dellete tag php 
Php :: merge two query results in laravel 
Php :: laravel insert timestamp now 
Php :: convert array to object php 
Php :: shortcut vsc select line up 
Php :: get taxonomy term meta by id 
Php :: array_push in php 
Php :: html_entity_decode (PHP 4 = 4.3.0, PHP 5, PHP 7, PHP 8) html_entity_decode — Convert HTML entities to their corresponding characters 
Php :: php info 
Php :: get country from ip 
Php :: How do I get the current date and time in PHP? 
Php :: php get keys and values from array 
Php :: how to set date in php 
Php :: word press get home page id 
Php :: codeigniter 3 send email smtp 
Php :: PHP Read File modes 
Php :: create project laravel 
Php :: php.ini location 
Php :: how to install php dependencies 
Php :: Server Requirements in laraavel 9 
Php :: php keys of array 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =