卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章16333本站已运行3317

在PHP中检查一个字符串是否以给定的单词开头

在PHP中检查一个字符串是否以给定的单词开头

Create a function to check whether a string begins with the specified string or not. The function should return TRUE on success or FALSE on failure.

The following is the syntax −

begnWith(str, begnStr)

Consider the following parameters in it to check −

  • str − The string to be tested

  • begnStr − The text to be searched in the beginning of the specified string.

Example

The following is an example −

Live Demo

<?php
   function begnWith($str, $begnString) {
      $len = strlen($begnString);
      return (substr($str, 0, $len) = = = $begnString);
   }
   if(begnWith("pqrstuvwxyz","p"))
      echo "True! It begins with p!";
   else
      echo "False! It isn't beginning with p!";
?>

输出

以下是输出 −

True! It begins with p!

卓越飞翔博客
上一篇: Python - 从字典中获取特定的嵌套级别项
下一篇: 如何在PHP中添加手机验证码功能提高用户注册安全性
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏