このphpスクリプトを見つけました:
// HTML を壊さないようにタグを削除 $string = strip_tags($string);
if (strlen($string) > 500) {
// truncate string $stringCut = substr($string, 0, 500); // make sure it ends in a word so assassinate doesn't become ass... $string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a href="/this/story">Read More</a>'; } echo $string;
webbiedave によって作成されます。今私の質問は、 strrpos で指定してスペースまたはドットを見つけるにはどうすればよいですか?
したがって、文字列を 22 に制限し、StackOverFlow のようなものがあれば、これまでで最高のサイトです --> 出力 StackOverFlow は ... そして、http://stackoverflow.comのようなものがあれば、これまでで最高のサイトです -- > のみを出力します ... 彼はスペースと文字列の長さ > 22 を見つけられませんでした。 -> http://stackoverflowになる... ?