doubi1624 2015-09-03 17:43
浏览 10
已采纳

PHP-从没有空格的字符串中解析单词?

My webpage has a variable, $currentPage. This is a string of the php token name of the page I'm currently on.

Example: All categories under the user section have names such as: uAdminNew, uAdminEdit, ect..

I would like for a way to parse out the uAdmin and just determine what is the last word (New and Edit) and call upon functions from there.

I have my navigation system working through these names, therefore I can't change the names or I would to make it easier to parse. Such as adding delimiters.

Is this something only Regex can solve or is there a simpler solution I'm missing? If this is Regex could you explain or provide a link as to how I would go about using it to test against a specific list of strings? I'm very new to it.

  • 写回答

3条回答 默认 最新

  • dongshen7561 2015-09-03 17:53
    关注

    Does the pagename always start with uAdmin? If so, you could split the string by "uAdmin" with explode():

    $page   = 'uAdminEdit';
    echo explode('uAdmin', $page)[1]; //Output: Edit
    

    Or simply remove "uAdmin" with str_replace():

    $page   = 'uAdminEdit';
    echo str_replace('uAdmin', '', $page); //Output: Edit
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊