Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get last word from string php

function getLastWord($string)
    {
        $string = explode(' ', $string);
        $last_word = array_pop($string);
        return $last_word;
    }
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

PREVIOUS NEXT
Code Example
Php :: laravel run specific feature test 
Php :: with message in laravel 
Php :: limited text show in laravel 
Php :: php ofreach 
Php :: next year php string 
Php :: insertgetid laravel 8 
Php :: boot add schema in laravel 
Php :: laravel tree 
Php :: install tymon jwt laravel 
Php :: array_key_exists 
Php :: clear console php 
Php :: laravel how to check if there are record exists 
Php :: artisan make migration with model 
Php :: php do not refresh page after submit post 
Php :: laravel validate datetime with datetime-local 
Php :: php time 
Php :: laravel eloquent get all 
Php :: php validate file type 
Php :: php get part of string 
Php :: laravel wherein example 
Php :: php nginx file not found 
Php :: wordpress get user profile picture 
Php :: wp plugins action link 
Php :: htmlspecialchars in php 
Php :: send email in php 
Php :: transfer file using file_get_content 
Php :: display image in html using php 
Php :: mysqli_connect php 
Php :: php postgresql 
Php :: get unique array from multidimentional array by value in php 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =