我有這個字串我想提取第一次出現的空白和最后一次出現的空白之間的字串
$string="...ence it is apparent why many are in the favour of the above stance. Another argument i...";
我想提取這部分it is apparent why many are in the favour of the above stance. Another argument
謝謝
uj5u.com熱心網友回復:
有很多方法可以做到這一點,這里是一種:
<?php
$str_arr = explode(" ", "Your long sentence here.");
$sub_arr = array_slice($str_arr, 1, count($str_arr)-2);
$extracted_str = implode(' ', $sub_arr);
echo $extracted_str; // long sentence
uj5u.com熱心網友回復:
$firstIndex = strpos($string, ' ') 1;
$lastIndex = strrpos($string, ' ');
substring($string, $firstIndex, $lastIndex - $firstIndex);
參考:PHP 中的 indexOf 和 lastIndexOf?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/473014.html
標籤:php
