PHP:如何选择字符串的特定部分
我想知道...我有两个字符串:
"CN=CMPPDepartemental_Direction,OU=1 - Groupes de sécurité,OU=CMPP_Departementale,OU=Pole_Ambulatoire,OU=Utilisateurs_ADEI,DC=doadei,DC=wan",
"CN=CMPPDepartemental_Secretariat,OU=1 - Groupes de sécurité,OU=CMPP_Departementale,OU=Pole_Ambulatoire,OU=Utilisateurs_ADEI,DC=doadei,DC=wan"
PHP中是否有一种方法可以选择这些字符串的第一部分?我只想选择 cmppdepartemental_direction 和 cmppdepartemental_secretariat 。
我曾经想过尝试使用substr()或trim(),但没有成功。
I was wondering... I have two strings :
"CN=CMPPDepartemental_Direction,OU=1 - Groupes de sécurité,OU=CMPP_Departementale,OU=Pole_Ambulatoire,OU=Utilisateurs_ADEI,DC=doadei,DC=wan",
"CN=CMPPDepartemental_Secretariat,OU=1 - Groupes de sécurité,OU=CMPP_Departementale,OU=Pole_Ambulatoire,OU=Utilisateurs_ADEI,DC=doadei,DC=wan"
Is there a way in php to select only the first part of these strings ? I would like to just select CMPPDepartemental_Direction and CMPPDepartemental_Secretariat.
I had thought of trying with substr() or trim() but without success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将
Preg_match
与RegexCN =(\ W+_ \ W+)
提取所需的部分:You should use
preg_match
with regexCN=(\w+_\w+)
to extract needed parts:如果字符串始终具有相同的结构,我建议使用自定义函数
find_by_keyword
- 这样您也可以搜索其他关键字。审查在这里。
If the strings always have the same structure, I recommend using a custom function
find_by_keyword
- so you can search for other keywords too.Examle here.