String resize functie
Kan er mij iemand helpen ik maakte deze 2 functies, maar wanneer ik title_resize een string meegeef komt uiteindelijk toch de volledige string eruit.
Ziet er iemand wat er fout is?
Alvast bedankt!
implode_functie
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<? { ?>
function implode_array ($values_array = null, $glue = ',', $array_check = true, $default_result = '0')
{
(string) $result = $default_result;
(array) $formatted_array = null;
if ($array_check)
{
if (is_array($values_array))
{
foreach ($values_array as $value)
{
$formatted_array[] = (empty($value)) ? 0 : $value;
}
}
else
{
$formatted_array[] = $default_result;
}
}
else
{
$formatted_array = $values_array;
}
$result = @implode($glue, $formatted_array);
return $result;
}
<? } ?>
function implode_array ($values_array = null, $glue = ',', $array_check = true, $default_result = '0')
{
(string) $result = $default_result;
(array) $formatted_array = null;
if ($array_check)
{
if (is_array($values_array))
{
foreach ($values_array as $value)
{
$formatted_array[] = (empty($value)) ? 0 : $value;
}
}
else
{
$formatted_array[] = $default_result;
}
}
else
{
$formatted_array = $values_array;
}
$result = @implode($glue, $formatted_array);
return $result;
}
<? } ?>
title resize_functie
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<? { ?>
function title_resize($text, $max_length = 15, $fulltext = false)
{
global $db;
(string) $output = null;
$text = $db->add_special_chars($text);
if ($fulltext)
{
$output = (strlen($text) > $max_length) ? substr($text, 0, $max_length - 3) . '... ' : $text;
}
else
{
$text_words = explode(' ', $text);
$nb_words = count($text_words);
for ($i=0; $i<$nb_words; $i++)
{
$display_output[] = (strlen($text_words[$i]) > $max_length) ? substr($text_words[$i], 0, $max_length-3) . '... ' : $text_words[$i];
}
$output = $db->implode_array($display_output, ' ', true, '');
}
return $output;
}
<? } ?>
function title_resize($text, $max_length = 15, $fulltext = false)
{
global $db;
(string) $output = null;
$text = $db->add_special_chars($text);
if ($fulltext)
{
$output = (strlen($text) > $max_length) ? substr($text, 0, $max_length - 3) . '... ' : $text;
}
else
{
$text_words = explode(' ', $text);
$nb_words = count($text_words);
for ($i=0; $i<$nb_words; $i++)
{
$display_output[] = (strlen($text_words[$i]) > $max_length) ? substr($text_words[$i], 0, $max_length-3) . '... ' : $text_words[$i];
}
$output = $db->implode_array($display_output, ' ', true, '');
}
return $output;
}
<? } ?>
Gewijzigd op 01/01/1970 01:00:00 door Lander Van Nieuwenhuyse
Er zijn nog geen reacties op dit bericht.