Woordafkort lukt niet
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
31
32
33
34
35
36
37
38
39
40
41
42
43
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
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
function afkorten($var, $lengte) {
$ret = $var;
if (strlen($ret) > $lengte) {
$ret = substr($ret, 0, $lengte-3)."...";
}
return $ret;
}
?>
<?php
include('../../config.php');
$query = mysql_query("SELECT * FROM gastenboek ORDER BY id");
while($rij = mysql_fetch_array($query))
{
echo "<div class=\"menutotaal\">";
echo "<div class=\"menuid\">";
echo $rij['id'];
echo "</div>";
echo "<div class=\"naam\">";
echo $rij['naam'];
echo "</div>";
echo "<div class=\"berichtdeel\">";
echo "<div style=\"margin-top:-12px\">";
$bericht = "$rij['bericht']";
echo $rij['bericht'] afkorten($bericht,10);
echo "</div></div>";
echo "<div class=\"datum\">";
echo $rij['datum'];
echo "</div>";
echo "<div class=\"deleteandupdate\">";
echo '<a href="delete.php?id='.$rij['id'].'"><img src="12.png" border="0" width="16" height="16" /> </a>';
echo '<a href="update.php?id='.$rij['id'].'"><img src="24.png" border="0" width="16" height="16" /> </a>';
echo "</div></div>";
[/code]
het lukt niet ik krijg deze melding
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\cms\beheer\modules\gastenboek\index.php on line 84
function afkorten($var, $lengte) {
$ret = $var;
if (strlen($ret) > $lengte) {
$ret = substr($ret, 0, $lengte-3)."...";
}
return $ret;
}
?>
<?php
include('../../config.php');
$query = mysql_query("SELECT * FROM gastenboek ORDER BY id");
while($rij = mysql_fetch_array($query))
{
echo "<div class=\"menutotaal\">";
echo "<div class=\"menuid\">";
echo $rij['id'];
echo "</div>";
echo "<div class=\"naam\">";
echo $rij['naam'];
echo "</div>";
echo "<div class=\"berichtdeel\">";
echo "<div style=\"margin-top:-12px\">";
$bericht = "$rij['bericht']";
echo $rij['bericht'] afkorten($bericht,10);
echo "</div></div>";
echo "<div class=\"datum\">";
echo $rij['datum'];
echo "</div>";
echo "<div class=\"deleteandupdate\">";
echo '<a href="delete.php?id='.$rij['id'].'"><img src="12.png" border="0" width="16" height="16" /> </a>';
echo '<a href="update.php?id='.$rij['id'].'"><img src="24.png" border="0" width="16" height="16" /> </a>';
echo "</div></div>";
[/code]
het lukt niet ik krijg deze melding
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\cms\beheer\modules\gastenboek\index.php on line 84
Gesponsorde koppelingen:
Hou variabelen buiten quotes! En je kunt niet zomaar 2 variabelen of een variabelen en een functie achter elkaar zetten. Als 't goed is moet je dat met een . kunnen oplossen.
Code (php)
Maar die variabele in een nieuwe variabele zetten zonder dat je er iets mee doet is sowieso onzin.
Ik heb een mooie afkortfunctie gevonden en iets aangepast:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
function truncate_end ($str, $limit = 25, $ending = '...') {
if (strlen ($str) > $limit) {
$text = strip_tags ($str);
$text = substr ($text, 0, $limit);
$text = substr ($text, 0, - (strlen (strrchr ($text, ' '))));
$text = $text . $ending;
}
return $text;
}
$str = 'The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.';
echo truncate_end ($str);
?>
function truncate_end ($str, $limit = 25, $ending = '...') {
if (strlen ($str) > $limit) {
$text = strip_tags ($str);
$text = substr ($text, 0, $limit);
$text = substr ($text, 0, - (strlen (strrchr ($text, ' '))));
$text = $text . $ending;
}
return $text;
}
$str = 'The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.';
echo truncate_end ($str);
?>



