将 +1 添加到从另一个站点获得的字符串 [英] Add +1 to a string obtained from another site

查看:28
本文介绍了将 +1 添加到从另一个站点获得的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从网站上获取的字符串.

I have a string I get from a website.

字符串的一部分是X2",我想将 +1 添加到 2.

A portion of the string is "X2" I want to add +1 to 2.

我得到的整个字符串是:

The entire string I get is:

20120815_00_X2

我想要的是添加X2"+1直到20120815_00_X13"

What I want is to add the "X2" +1 until "20120815_00_X13"

推荐答案

此解决方案有效(无论 X 后面的数字是多少):

This solution works (no matter what the number after X is):

function myCustomAdd($string)
{

$original = $string;

$new = explode('_',$original);

$a = end($new);

$b = preg_replace("/[^0-9,.]/", "", $a);

$c = $b + 1;

$letters = preg_replace("/[^a-zA-Z,.]/", '', $a);

$d = $new[0].'_'.$new[1].'_'.$letters.$c;

return $d;

}

var_dump(myCustomAdd("20120815_00_X13"));

输出:

string(15) "20120815_00_X14"

这篇关于将 +1 添加到从另一个站点获得的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆