如何在codeigniter中拆分student_no?

发布于 2024-12-10 19:35:10 字数 384 浏览 0 评论 0原文

当我单击完成按钮时,我想增加 Student_no 。

student_no : ABS10000

所以我想拆分student_no并增加一个。如何?

我可以使用character_limiter()吗?

$string1 = "ABS100000";
$string1 = character_limiter($string1, 2);

$string2 = "ABS100000";
$string2 = character_limiter($string2, 3,8);
$string = $string + 1;
echo $string1;
echo $string2;

这是正确的...

I want increase the student_no, when i click the finish button.

student_no : ABS10000

So i want to split the student_no and increase one. How?

Can i use character_limiter()?

$string1 = "ABS100000";
$string1 = character_limiter($string1, 2);

$string2 = "ABS100000";
$string2 = character_limiter($string2, 3,8);
$string = $string + 1;
echo $string1;
echo $string2;

This is correct...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情洁癖 2024-12-17 19:35:10

您使用该辅助函数的方式非常错误。另外,您的代码在某些时候没有什么意义。

character_limiter()属于Text helper,它的目的主要是提供格式化方面的帮助;看看配套的功能,你就会看到它。

另外,第三个(可选)参数应该是附加在修剪字符串末尾的文本,例如省略号。根据您的初衷,您的第二个示例“将字符串限制为 3 个字符并在末尾添加 8”,这显然是错误的。

我不知道有任何帮助器函数(这里或其他帮助器)可以做你想做的事情,但由于你在 php 中编码,我不知道为什么不能只做类似的事情(我知道可能有是更好的方法来做到这一点):

$string1 = str_replace('ABS','',"ABS100000"); // becomes 100000
$string1 = intval($string1) + 1; //100000 is cast to INT and then 1 is added;
$new_string = 'ABS'.$string1; //gives ABS100001;

我假设“ABS”是固定的,您只想增加该字符串的数字部分。如果不是,请在您的问题中更清楚并添加相关信息。

You're using that helper function quite wrong. Also, your code makes little sense at some points.

character_limiter() belongs to the Text helper, it's aim is to provide help in formatting, mostly; look at the companion functions and you will see it.

Also, the third (optional) parameter should be a text appended at the end of the trimmed string, something such an ellipsis, for ex. Your second example, which tells to "limit the string to 3 characters and add and 8 at the end" is just plainly wrong, according to your original intentions.

I'm not aware of any helper function (here or in other helpers) that can do what you want, but since you're coding in php, I don't know why can't just do something like (I know there might be better ways to do this):

$string1 = str_replace('ABS','',"ABS100000"); // becomes 100000
$string1 = intval($string1) + 1; //100000 is cast to INT and then 1 is added;
$new_string = 'ABS'.$string1; //gives ABS100001;

I'm assuming 'ABS' is something fixed and you just want to increment the numerical part of this string.If not, please be more clear in you question and add the relevant informations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文