doukun0888 2013-10-23 10:07
浏览 55
已采纳

str_word_count函数中的数字值和特殊字符

I want to numeric values and special charectors values in str_word_count() so how can do that.

example:

$str = str_word_count("B2B my78:test@ Number&10",1);
print_r($str);

Output

Array (

[0] => B
[1] => B
[2] => my
[3] => test
[4] => Number 

)

but I want to Out put Like this

Array (

[0] => B2B
[1] => my78:test@
[2] => Number&10 

)

  • 写回答

4条回答 默认 最新

  • dora12345678 2013-10-23 10:23
    关注

    preg_match_all behaves almost like st_word_count, in that it can return the number of matches and an array of words in your string. By using it, you can have the utmost flexibility in defining what exactly constitutes a "word."

    $count = preg_match_all('/[a-zA-Z0-9@&:]+/', $str, $matches);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效