简体   繁体   English

PHP rtrim()或类似的函数,用于从字符串中删除X个字符

[英]PHP rtrim() or similar function for removing X amount of characters from string

This should be pretty basic. 这应该很基本。 I've searched all over the best matching function (as far as I can see from PHP Manual is rtrim) 我搜索了所有最佳匹配函数(据我从PHP Manual所看到的是rtrim)

I've got a string. 我有绳子。 I want to remove X-amount of characters from, specifically the first 4 characters from the string. 我要删除X字符,特别是字符串中的前4个字符。

EXAMPLE: 例:

Fri, Dec 1, 2017 2017年12月1日,星期五

Sat, Dec 2, 2017 2017年12月2日,星期六

Sat, Dec 2, 2017 2017年12月2日,星期六

I would like to remove the first 4 characters from the left including white space after comma in order for me to have a date I can work with without day of week. 我想从左边删除前4个字符(包括逗号后的空白),以便让我有一个可以在没有星期几的情况下使用的日期。

Now according to manual and W3Schools rtrim() enables you to do the above. 现在根据手册和W3Schools的rtrim()可以执行上述操作。 However as I understand it, you have to put in the characters / text you want to be trimmed from string. 但是据我了解, 您必须输入要从字符串中修剪掉的字符/文本。

My problem is the days of the week will alternate from MON - SUN thus I can not put specific characters. 我的问题是星期几与星期一-太阳交替出现,因此我不能放置特定字符。

I'm trying to trim with index numbers starting from left 0-4 我正在尝试使用从左0-4开始的索引号进行修整

So at the end: 所以最后:

Fri, Dec 1, 2017 2017年12月1日,星期五

Should read 应该读

Dec 1, 2017 2017年12月1日

尝试;

substr("Fri, Dec 1, 2017", 5);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM