substr 字符串截取
<!DOCTYPE html>
<html>
<body><?php</body>
echo substr("Hello world",0,10)."<br>";
echo substr("Hello world",1,8)."<br>";
echo substr("Hello world",0,5)."<br>";
echo substr("Hello world",6,6)."<br>"; echo substr("Hello world",0,-1)."<br>";
echo substr("Hello world",-10,-2)."<br>";
echo substr("Hello world",0,-6)."<br>";
echo substr("Hello world",-2-3)."<br>";
?>
</html>
php 去掉字符串的最后一个字符
原字符串1,2,3,4,5,6,
去掉最后一个字符",",最终结果为1,2,3,4,5,6
代码如下:
- $str = "1,2,3,4,5,6,";
- $newstr = substr($str,0,strlen($str)-1);
- echo $newstr;
- //echo 1,2,3,4,5,6
系统自带的函数即可实现这样的效果,两种方法:
- substr($str, 0, -1)
- //函数2
- rtrim($str, ",")
substr 字符串截取的更多相关文章
- JavaScript substr() 字符串截取函数使用详解
substr 定义和用法 substr() 方法可在字符串中抽取从 start 下标开始的指定数目的字符. 语法 stringObject.substr(start,length) 如果 length ...
- JS的slice、substring、substr字符串截取
JS中截取一个字符串的三种方法:字符串.slice(开始索引,结束索引)字符串.substring(开始索引,结束索引)字符串.substr(开始索引,截取的长度) 如果需要截取到该字符串的最后,可以 ...
- ThinkPHP 模板substr的截取字符串函数
ThinkPHP 模板substr的截取字符串函数在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $start ...
- javascript字符串截取的substring、substr和slice
本文详细的介绍了javascript中substring().substr()和slice()三个JS字符串截取的方法,substring()方法用于提取字符串中介于两个指定下标之间的字符.subst ...
- 字符串截取函数slice, substring, substr
在日常项目需求中,常常会遇到需要截取字符串操作的工作,而ECMAScript为我们提供了原生的截取字符串的函数,而且提供了三个:slice, substring, substr.我们怎么判断在什么时候 ...
- 字符串截取 及 substr 和 substring 的区别
1..字符串截取 str.substr(0, 1) // 获取字符串第一个字符 str.substr(-1) // 获取字符串最后一个字符 str.charAt(str.length - 1) // ...
- 数组遍历 map()、forEach() 及 字符串切割 split() / 字符串截取 slice()、substring()、substr()
JS数组遍历的几种方式 JS数组遍历,基本就是for,forin,foreach,forof,map等等一些方法,以下介绍几种本文分析用到的数组遍历方式以及进行性能分析对比 第一种:普通for循环 代 ...
- js 字符串截取 substring() 方法、 substr() 方法、slice() 方法、split() 、join();
三种 js 截取字符串的方法: substring() 方法: substr() 方法: slice() 方法: 1.:substring() 方法:string.substring(from, to ...
- PHP substr() 函数截取中文字符串乱码
用PHP substr() 函数截取中文字符串乱码,换PHPmb_substr() 函数即可
随机推荐
- Django学习:连接Mysql数据库
开发环境: Windows 10 Python 3.7.4 Django 2.2.6 Mysql 8.0.17 承接上一节:https://www.cnblogs.com/daydayupup/p/1 ...
- LintCode上的一道算法面试题: 数字的统计
说到数字的统计,小时候的数学课大家都应该有学过,但数字太多太复杂的,手动肯定耗时间不说还很容易出错.所以今天分享一下如何用程序来完成. Have you met this question in a ...
- windows10 L2tP nat 下无法连接的处理
事件查看器中没有错误代码显示. Windows 10 L2TP/IPsec Manual Setup Instructions Bold items are things you will click ...
- [].slice.call(arguments,1) 个人理解
var arr = []; [] == arr; 假设 var arr = [1,2,3,4,5]; 那么 arr.slice(1,2) == [2]; 通过 slice.call 才能使用call显 ...
- hbuilderX创建vue项目之添加router路由(前端萌新)
作为一个刚刚接触前端不久的新人来说,熟悉了一种目录结构或者项目创建方法以后,恨不得一辈子不会变! 可是人要生活,就要工作,既然是打工,当然要满足雇佣者的要求. 今天我来说说 hbuilderX 这个开 ...
- 布尔(boolean)代数趣味学习法
今天,我想出来一个学习布尔(boolean)代数的趣味方法: 比如:逻辑与(&)运算 逻辑里面就是并且形象的理解就是:从卧室里面外出,必须 卧室的门打开 “并且” 最外面的门打开,才能出去.用 ...
- Codeforces Round #346 (Div. 2) C题
C. Tanya and Toys In Berland recently a new collection of toys went on sale. This collection consist ...
- Connect AS400 through firewall(JDBC will require ports: 449, 8470, 8471, and 8476)
What TCP ports are used by ODBC to connect to the DB2/400? 8471/9471 http://search400.techtarget.co ...
- BERT中文 添加 early_stop
Step1:建一个hook early_stopping_hook = tf.contrib.estimator.stop_if_no_decrease_hook( estimator=estimat ...
- HMM 隐马尔科夫 Python 代码
import numpy as np # -*- codeing:utf-8 -*- __author__ = 'youfei' # 隐状态 hidden_state = ['sunny', 'rai ...