Jump to content
php.lv forumi

Teksta samazināšana


Wuu

Recommended Posts

/*teksta samazināšana */
function crop ($text) {
if (strlen($text) > 600) {
	$text = substr($text,0,600);
	$text = trim($text);
	$text = explode(" ", $text, -1);
	$text = implode(" ",$text);
	$text .='...';
}
return $text;
}

 

Viss strādā ,bet nepatīk tā pēdējā fīča

$text = explode(" ", $text, -1); //dzēšam pēdējo vārdu

$text = implode(" ",$text); // Saliekam atpakaļ :)

 

Google meklēju bet neko jēdzīgu neatradu ,tāpēc uzrakstīju pac. Bet man liekas kaut kā palēni es to fīču ar pēdējā vārda noņemšanu uzrakstīju ,ieteikumi?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...