function truncate
Chris
16/02/2008 15:52:00Hoi, heb de volgende funtie in mijn php staan:
daarvoor staat:
$text = $item->get_description();
en daarna echo't hij $text, hij kort echter niets in... wat doe ik verkeerd?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
function truncate($text,$numb,$etc = "...") {
$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text," "));
$punctuation = ".!?:;,-"; //punctuation you want removed
$text = (strspn(strrev($text), $punctuation)!=0)
?
substr($text, 0, -strspn(strrev($text), $punctuation))
:
$text;
$text = $text.$etc;
}
$text = htmlentities($text, ENT_QUOTES);
return $text;
}
?>
function truncate($text,$numb,$etc = "...") {
$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text," "));
$punctuation = ".!?:;,-"; //punctuation you want removed
$text = (strspn(strrev($text), $punctuation)!=0)
?
substr($text, 0, -strspn(strrev($text), $punctuation))
:
$text;
$text = $text.$etc;
}
$text = htmlentities($text, ENT_QUOTES);
return $text;
}
?>
daarvoor staat:
$text = $item->get_description();
en daarna echo't hij $text, hij kort echter niets in... wat doe ik verkeerd?