Php 는 문자열의 마지막 n 단어를 추출합니다

코드 예제

1
0

문자열 php 에서 마지막 단어 가져 오기

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

php 는 문자열의 마지막 n 단어를 추출합니다

<?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"
} */

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................