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条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line