dsxsou8465 2015-04-03 03:15
浏览 127
已采纳

PHP匹配特定的句子字母,只获得单词

I'm tiring to write a PHP code for get matched words by using letters, its not the same strpos.

 ex
    $string="How are you robin ?";
    $searchletters="yo";


 in this  "$string" when i search "$searchletters" i need to get 
 the word "you" which have you letters, 

anyone have a idea how to implement this with PHP. Thank You

  • 写回答

2条回答 默认 最新

  • dtjzpg5313 2015-04-03 03:16
    关注

    You can use this regex:

    $re = '/\b' . preg_quote($searchletters, '/') . '\w*\b/';
    
    preg_match($re, $string, $m);
    echo $m[0] . "
    ";
    //=> you
    

    RegEx Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部