2016-04-11 19 views
-2

PHP入力から文字を取り除く必要があります。PHPの文字列の一部を抽出する

たとえば、バージョン番号があり、最後の部分のみが必要です。

は私が唯一の必要私だけ123
14.3.21を考える必要14.1.2.123を考えると21

私はPHPでちょうどそれらの数値を得ることができる方法はありますか?

答えて

1

あなたはこれを試すことができます -

$temp = explode('.', $version); // explode by (.) 
echo $temp[count($temp) - 1]; // get the last element 

echo end($temp); 

それとも

$pos = strrpos($version, '.'); // Get the last (.)'s position 
echo substr(
    $version, 
    ($pos + 1), // +1 to get the next position 
    (strlen($version) - $pos) // the length to be extracted 
); // Extract the part 

strrpos()substr()strlen()explode()

+0

私は 'strrpos'答えを追加しましたが、後半に5秒を持って:) 1 –

+2

'エコー終了($ temp);' –

+0

偉大な@ダゴン。逃した1. :) –

関連する問題