Home  >  Article  >  Backend Development  >  php截取字符串问题!在线等 在线结贴

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

WBOY
WBOYOriginal
2016-06-23 14:26:51810browse

yybb_cx.
yybb_xdf.

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

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


回复讨论(解决方案)

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

  这是把原先的替换了吗?

 

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


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

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

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

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

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

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


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

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

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

不喜欢正则那就这样截取

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

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

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

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

Statement:
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