【问题标题】:how to truncate the string, or to extract a portion of the value from a string in php [duplicate]如何截断字符串,或从php中的字符串中提取部分值[重复]
【发布时间】:2020-06-19 07:28:01
【问题描述】:

你好,我的值是 1284&kec=220107&prop=220000

这里我要取前面的数字&前面的数字 并不总是三个字母,有时是两个字母,有时是 还有一个,&

之后如何删除或删除值
example : 1284&kec=220107&prop=220000
result value = 1284

example : 11&kec=2332&prop=563454
result value = 11

你能举个例子吗?

【问题讨论】:

  • 来自字符串? php中有一个叫做strpossubstr的东西
  • 你可以使用chop()函数,答案如下。

标签: php codeigniter substr


【解决方案1】:

您可以使用explode()string 转换为array,然后得到您想要的。像这样-

$example = '1284&kec=220107&prop=220000';
$ex = explode("&kec", $example); // convert it to array where $kec is found
$value = $ex[0]; // output: 1284 // the first key will hold the value before $kec

$example2 ='11&kec=2332&prop=563454';
$ex = explode("&kec", $example2);
$value = $ex[0]; // output: 11

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-24
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多