如何通过PHP从字符串中获取子字符串? [英] How to get a substring from string through PHP?
本文介绍了如何通过PHP从字符串中获取子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您想将显示的用户名(例如abcd@somedomain.com)更改为仅abcd. 所以为此,我应该剪切从@开始的部分.
Hi want to change the displayed username like abcd@somedomain.com to only abcd. so for this i should clip the part starting from @.
我可以通过Java或C#中的variablename.substring()函数非常轻松地完成此操作,但是我不了解PHP的语法. 所以帮我做到这一点.
I can do this very easily through variablename.substring() function in Java or C# , but I m not aware with the syntax of PHP. So help me do that .
假设我有类似的变量.
$username = "abcd@somedomain.com";
$username = some
字符串操作函数应该在这里调用; 以便 echo $ username; 只能产生abcd.
string manipultion functiona should get called here ; so that echo $username; can results in abcd only.
推荐答案
尝试一下:
$username = substr($username, 0, strpos($username, '@'));
这篇关于如何通过PHP从字符串中获取子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文