PHP8: new str_* function

This commit is contained in:
Sunch 2024-08-17 20:11:55 +08:00
parent 69385e16f2
commit 1275a4558c
7 changed files with 15 additions and 15 deletions

View file

@ -190,8 +190,8 @@ class PlayerAPI{
}
break;
case "tp":
if(count($args) <= 2 or substr($args[0], 0, 2) === "w:" or substr($args[1], 0, 2) === "w:"){
if((!isset($args[1]) or substr($args[0], 0, 2) === "w:") and isset($args[0]) and ($issuer instanceof Player)){
if(count($args) <= 2 or str_starts_with($args[0], "w:") or str_starts_with($args[1], "w:")){
if((!isset($args[1]) or str_starts_with($args[0], "w:")) and isset($args[0]) and ($issuer instanceof Player)){
$name = $issuer->username;
$target = implode(" ", $args);
}elseif(isset($args[1]) and isset($args[0])){
@ -297,7 +297,7 @@ class PlayerAPI{
}
public function teleport(&$name, &$target){
if(substr($target, 0, 2) === "w:"){
if(str_starts_with($target, "w:")){
$lv = $this->server->api->level->get(substr($target, 2));
if($lv instanceof Level){
$origin = $this->get($name);

View file

@ -31,7 +31,7 @@ class TimeAPI{
$p = strtolower(array_shift($args));
switch($p){
case "check":
if(substr($args[0] ?? "", 0, 2) === "w:"){
if(str_starts_with($args[0] ?? "", "w:")){
$levelName = preg_replace("/w:/", "", $args[0]);
$level = $this->server->api->level->get($levelName);
if($level instanceof Level){
@ -44,7 +44,7 @@ class TimeAPI{
$output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n";
break;
case "add":
if(substr($args[1] ?? "", 0, 2) === "w:"){
if(str_starts_with($args[1] ?? "", "w:")){
$levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName);
if($level instanceof Level){
@ -65,7 +65,7 @@ class TimeAPI{
$output .= "Added $addTime ticks" . $world . "\n";
break;
case "set":
if(isset($args[1]) and substr($args[1], 0, 2) === "w:"){
if(isset($args[1]) and str_starts_with($args[1], "w:")){
$levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName);
if($level instanceof Level){
@ -92,7 +92,7 @@ class TimeAPI{
case "day":
case "sunset":
case "night":
if(count($args) > 1 && substr($args[1], 0, 2) === "w:"){
if(count($args) > 1 && str_starts_with($args[1], "w:")){
$levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName);
if($level instanceof Level){

View file

@ -548,7 +548,7 @@ class PocketMinecraftServer{
$this->custom["times_" . $CID] = 0;
}
$ln = 15;
if($this->description == "" or substr($this->description, -1) != " "){
if($this->description == "" or !str_ends_with($this->description, " ")){
$this->description .= " ";
}
$txt = substr($this->description, $this->custom["times_" . $CID], $ln);

View file

@ -4,7 +4,7 @@ set_time_limit(0);
if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT");
if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){
$time = time();
$time -= $time % 60;
//Example: USA
@ -24,7 +24,7 @@ if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set($d);
}else{
$d = @date_default_timezone_get();
if(strpos($d, "/") === false){
if(!str_contains($d, "/")){
$d = timezone_name_from_abbr($d);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);

View file

@ -120,7 +120,7 @@ $inc = get_included_files();
$inc[] = array_shift($inc);
$srcdir = realpath(FILE_PATH . "src/");
foreach($inc as $s){
if(strpos(realpath(dirname($s)), $srcdir) === false and strtolower(basename($s)) !== "pocketmine-mp.php"){
if(!str_contains(realpath(dirname($s)), $srcdir) and strtolower(basename($s)) !== "pocketmine-mp.php"){
continue;
}
$sha1sum ^= sha1_file($s, true);

View file

@ -140,7 +140,7 @@ function arguments($args){
foreach($args as $arg){
// Is it a command? (prefixed with --)
if(substr($arg, 0, 2) === '--'){
if(str_starts_with($arg, '--')){
$value = preg_split('/[= ]/', $arg, 2);
$com = substr(array_shift($value), 2);
@ -152,7 +152,7 @@ function arguments($args){
}
// Is it a flag? (prefixed with -)
if(substr($arg, 0, 1) === '-'){
if(str_starts_with($arg, '-')){
$ret['flags'][] = substr($arg, 1);
continue;
}

View file

@ -87,7 +87,7 @@ class Utils{
* PHP8 has internal function for doing it: {@link str_ends_with}
*/
public static function endsWith($str, $check) {
return substr($str, -strlen($check)) === $check;
return str_ends_with($str, $check);
}
public static function hasEmoji($s){
@ -148,7 +148,7 @@ class Utils{
public static function getOS(){
$uname = php_uname("s");
if(stripos($uname, "Darwin") !== false){
if(strpos(php_uname("m"), "iP") === 0){
if(str_starts_with(php_uname("m"), "iP")){
return "ios";
}else{
return "mac";