PHP忽略第5个字符?(PHP ignore 5th character?)

我有一个简单的PHP问题。

在我的PHP中 ,我有这个:

$variable = 'howareyou';

有可能以某种方式修改代码,因此它只计算变量的第6个字符?

所以之后,当回声

它会说怎么代替你怎么样 。

我需要用数字过滤它,比如5号或6号 。 这可能吗?

谢谢!

I have a simple php question.

in my php, I have this:

$variable = 'howareyou';

is it possible to somehow modify the code so it only counts up to 6th character of the variable?

so after, when echo'd

it would say howare instead of howareyou.

I need to filter it with a number, like 5th or 6th. Is this possible?

Thanks!

原文:https://stackoverflow.com/questions/5321237

更新时间:2019-12-05 11:40

最满意答案

只需使用子串。

$variable = substr($variable, 0, 6)

语法是substr(string,start,length),并记住它们是零索引的。

Just use substring.

$variable = substr($variable, 0, 6)

The syntax is substr(string, start, length) and remember that these are zero indexed.

2011-03-16

相关问答

它错过了最后一个值,因为如果找到+则只添加数字。 所以对于最后一个unparsedNumber你永远不会输入else if (c == '+')块。 让我建议一个更紧凑的解决方案: public int addFromString(string str)

{

string trimmed = str.Trim();

if (str.StartsWith("+") || str.EndsWith("+")) return 0; // invalid -> return immedia

...

你可以做line = line[1:]去掉第一个字符。 但是,如果你这样做,你应该添加一个断言,第一个字符确实是一个选项卡,以避免在没有领先选项卡的情况下损坏数据。 有一个更容易的选择,也可以处理其他几种情况,如果要删除的东西不存在,则不会中断任何事情。 您可以使用line = line.strip()所有前导和尾随空白。 或者,使用.lstrip()仅剥离前导空白,如果要保留其他空白并只删除制表符,则可以将'\t'作为参数添加到任一方法调用中。 You could do line = line[

...

只需使用子串。 $variable = substr($variable, 0, 6)

语法是substr(string,start,length),并记住它们是零索引的。 Just use substring. $variable = substr($variable, 0, 6)

The syntax is substr(string, start, length) and remember that these are zero indexed.

^(?!(.)\1+$)[XO]{5}$

试试看。 https://regex101.com/r/uK9cD8/1 ^(?!(.)\1+$)[XO]{5}$

Try this.See demo. https://regex101.com/r/uK9cD8/1

这将做到这一点... ^\w\d\.(\d{3})\s(?:([YN])|\d)\s*(\d:\d{2})$

我对你的正则表达式做了一些其他的改变,因为我更容易根据你的数据重写它,然后尝试修改你的数据。 这将捕获Y或N,否则它不会捕获该组中的任何内容。 我也试图用你的持续时间正则表达式更具体。 更新:这适用于您的新需求... ^\w\d\.(\w{3})\s(?:([YN])|\d|\s)\s*(\d:\d{2})$

你可以在这里看到它处理你的数据... http://regexr.com?3

...

你能尝试使用str_replace吗? $datetogoto = $_GET['datetogoto'];

$datetogoto = str_replace("-","", $datetogoto);

参考: http : //us1.php.net/str_replace 或者,如果你想获得在查询字符串中发送的任何日期格式,那么使用urlencode() header('Location: ../index.php?newsdate='.urlencode($datetogoto));

...

\字符是一个转义字符。 你得到一个语法错误,因为\"是在String文字中放置一个"字符的转义序列。 要在String文本中放置\ ,您需要使用\\ (第一个\转义第二个\的特殊含义)。 所以一个语法正确的陈述是: String[] parts = "\u0041\u006e\u0064\u0072\u006f\u0069\u0064".split("\\");

但是这不会给你想要的,因为第一个参数不包含任何\字符。 (另外, split()方法需要一个正则表达式,而\不是一个有效的正则表达式

...

您可以在for循环中使用范围功能: text = "Do you like green eggs and ham? I like them, Sam I am! Do you like green eggs and ham, Sam? Do you like them, Sam I am?"

transform = ''

for l in range(4, len(text), 5):

transform += text[l]

#remove spaces (as your examp

...

由于 - 字符串的长度为3或4,因此在-之后只能获取3个字符。 这是代码片段 LEFT(@a, CHARINDEX('-', @a) + 3) = LEFT(@b, CHARINDEX('-', @b) + 3)

Since the length of sub-string after - is either 3 or 4, you just only fetch 3 characters after -. Here is code snippet LEFT(@a, CHARINDEX('-',

...

使用此基于交替的正则表达式: \.:\d{3}|:(\d{3})

并抓住你所在比赛的第一组。 RegEx演示 Use this alternation based regex: \.:\d{3}|:(\d{3})

And grab captured group #1 for your matches. RegEx Demo

php ignore special characters,PHP忽略第5个字符?(PHP ignore 5th character?)相关推荐

  1. php ignore special characters,PHP htmlspecialchars() 函數--防注入字符轉義函數

    更多實例 例子 1 把一些預定義的字符轉換為 HTML 實體:<?php $str = "Bill & 'Steve'"; echo htmlspecialchars ...

  2. 错误日志:Syntax Error: Error: Unexpected ‘/‘. Escaping special characters with \ may help.

    在运行Vue项目的时候出现错误: ERROR Failed to compile with 1 error 9:55:33error in ./src/components/index/SimpleH ...

  3. [LeetCode] 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串...

    Given a string S, find the length of the longest substring T that contains at most two distinct char ...

  4. python 问题Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.

    参考链接: (1)https://www.cnblogs.com/HANYI7399/p/6080070.html (2)https://blog.csdn.net/weixin_30780649/a ...

  5. eclipse svn提交忽略文件及文件夹,ignore设置无效..

    如果之前提交过此文件,就不能设置忽略该文件了.所以第一次提交的时候要搞清楚再提交. [亲测,的确如此,用 Windows -> Preferences -> Team -> Igno ...

  6. eclipse svn不能忽略文件及文件夹,ignore设置无效 ?

    SVN这块做得不好,如果之前提交过此文件,就不能设置忽略该文件了.所以第一次提交的时候要搞清楚再提交. [ 亲测,的确如此,用 Windows -> Preferences -> Team ...

  7. MySQL insert ignore/ update ignore 不只用来忽略id重复

    摘自https://www.mysqlzh.com/doc/126/254.html 如果您在一个INSERT语句中使用IGNORE关键词,在执行语句时出现的错误被当作警告处理.例如,没有使用IGNO ...

  8. smartsvn 忽略文件夹_svn ignore 的用法(忽略文件及目录)

    svn ignore 的用法(忽略文件及目录) 若想创建了一个文件夹,并且把它加入版本控制,但忽略文件夹中的所有文件的内容: $ svn mkdir spool $ svn propset svn:i ...

  9. [plugin:commonjs] Unexpected ‘/‘. Escaping special characters with \ may help.错误分析

    错误原因:样式表里使用了//作注释 解决办法:把'//tab样式'去掉就可以了 补充:css中注释使用'/**/'

最新文章

  1. windows10 计算器无法打开(转)
  2. node.js下载安装并配置WebStrom
  3. 三校生计算机模拟试题1,甘肃省2015年“三校生”考试摸拟试题1
  4. Spring boot全面接管Spring MVC
  5. 从零开始搭建spring-cloud(2) ----ribbon
  6. linux刷除U盘grub,删除linux系统出现grub rescue
  7. 如何在OS X中打开或关闭鼠标定位器
  8. php 处理二维数组(去除重复项,排序,转换,去空白等)
  9. 加密货币究竟是不是泡沫?
  10. Git命令集之六——查看仓库状态
  11. glide源码中包含了那种设计模式_源码中的设计模式-单例模式
  12. 企业微信自定义应用页面授权过程
  13. angularJs-基础用法
  14. linux下无线USB网卡驱动安装
  15. 计算机平面设计是什么学的什么,计算机平面设计主要学什么?
  16. 电脑接html线没反应,笔记本插上网线没反应怎么办【解决方法】
  17. 交换机、路由器、服务器、存储选型
  18. 小学五计算机课程安排,2021年小学五年级信息技术教学计划(干货4篇)
  19. 直流斩波电路在matlab中的建模与仿真,基于MATLAB/Simulink的直流斩波电路分析
  20. 为什么要使用API Key 和Secret Key

热门文章

  1. 页面的缓存与不缓存设置
  2. APL开发日志--2013-01-17
  3. 转--javascript 数组
  4. 牛客18987 粉嘤花之恋(矩阵快速幂、斐波那契数列)
  5. 米家电磁炉显示e10_米家电磁炉e10故障怎么回事
  6. java 数据类型 string_java的基本数据类型和引用数据类型都有哪些,string属于什么类型...
  7. python设计编程体验中心_试学了风变编程的Python小课体验课,觉得课程模式很有趣,报名正式课程应该注意什么?...
  8. C++获取指向二维数组的首元素指针
  9. Elsevier LaTeX时间-年份(author-year)两种引用格式
  10. python读取与写入json+csv变成coco的json文件+安装labelme