php - 如何截断字符串,或从 php 中的字符串中提取部分值
问题描述
你好,我的值是 1284&kec=220107&prop=220000
这里我要取前面的数字&前面 的数字并不总是三个字母,有时两个字母有时也是一个,如何删除或删除&后面的值
example : 1284&kec=220107&prop=220000 result value = 1284 example : 11&kec=2332&prop=563454 result value = 11
能给我举个例子吗?
解决方案
您可以使用explode()
将其转换string
为an 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
推荐阅读
- python - Python和硒:强制没有下载窗口
- xquery - MarkLogic 查询耗时过长
- python - Kivy:函数\方法不能从另一个类工作
- javascript - fullpage.js 不能与锚链接正常工作
- react-native - React Native 示例应用程序无法在 Expo Snack 中运行
- c++11 - ubunt16.04中的fblualib安装
- mysql - 通过 id 从许多表中查询 SQL 选择?
- angular - 为什么我的 Angular 应用程序在 StackBlitz 上运行时会出错?
- php - 将表格导出到excel时如何使用utf-8
- python - sumy LexRankSummarizer() 输出文本的正确格式