开发者

how to limit search box words in php

开发者 https://www.devze.com 2023-03-14 10:46 出处:网络
php How to limit words in a search box? I want limit words within 30 words and do not broken the phrase.

php How to limit words in a search box? I want limit words within 30 words and do not broken the phrase.

I think it should combine strlen and ex开发者_JAVA技巧plode, but how to? and how to notice the custom when he is typing words?

Thanks.


That's javascript related not PHP.

You may want to use jQuery and attach an onChange event.

If you need the PHP script it's:

echo implode( ' ', array_slice(explode(' ',$search),0,30) ); //> Expensive


You can check PHP's str_word_count function . You can count words .


$string = preg_replace('/^((?:\s*\w+){0,30}).*$/s', '$1', $string);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号