php截取字符串问题!在线等 在线结贴

WBOY
Release: 2016-06-23 14:26:51
Original
812 people have browsed it

yybb_cx.
yybb_xdf.

就像上面的字符串。我只需要_后面和.前面的字母  

比如以上两个  我需要的分别就是  cx 和 xdf   应该怎么处理?


回复讨论(解决方案)

$s=<<<htmlyybb_cx.yybb_xdf.html;preg_match_all('/_(.+?)\./s',$s,$m);print_r($m[1]);
Copy after login
Copy after login

这是把原先的替换了吗?



$s=<<<htmlyybb_cx.yybb_xdf.html;preg_match_all('/_(.+?)\./s',$s,$m);print_r($m[1]);
Copy after login
Copy after login


大哥我没搞过php 别搞那么复杂。

其实我要的很简单,就是说

$datas = $_POST["shujuku"]; //我这有个传送过来的字符串 赋给了 $datas 那个字符串就是yybb_xdf.这个样子的。

我现在是需要 把这个$datas按照我的要求把_和.之间的字符串截取出来 赋给一个新的变量。

preg_match('/_(.+?)\./s',$data,$m);$a=$m[1];  //$a 就是你要的变量
Copy after login
Copy after login

preg_match('/_(.+?)\./s',$data,$m);$a=$m[1];  //$a 就是你要的变量
Copy after login
Copy after login


大哥。。只有一个点。。。

我取的是 .之前和_之后的字母 我现在用你最后的变量$a 娶到的只有一个.

不可能吧,贴出你的代码看看。

不喜欢正则那就这样截取

$a = "yybb_cx.";$a = substr(substr($a,5),0,-1);echo $a;
Copy after login

不对不对 是我搞错了。 不应该是.之前。 只需要下划线之后的字母就可以!!!!

$a = "yybb_cx.";$a = substr($a,5);echo $a;
Copy after login

$s = 'yybb_cx.';strtok($s, '_');$a = strtok('.');echo $a; //cx
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!