Съкращаване на текст

spektur

Registered
някой може ли да помогне за този код, каква му е грешката че не се съкращава името на песента



<?php
$query = mysql_query("SELECT * FROM songs top ORDER BY view DESC LIMIT 15");
while ($row = mysql_fetch_array($query))
{
echo '<a href="index.php?m=play&id='.$row['id'].'"><font size="2" color="black"> - '.$row['artist'].'-'.$row['title'].'..</a><br/>';



}
?>
 
<?php
$query = mysql_query("SELECT * FROM songs top ORDER BY view DESC LIMIT 15");
while ($row = mysql_fetch_array($query))
{

$txt = $row['artist'].' - '.$row['title'];
if(strlen($txt) > 30)
{

echo '<a href="index.php?m=play&id='.$row['id'].'"><font size="2" color="black"> - '.substr($txt, 0, 30).'..</a><br/>';
} else {
echo '<a href="index.php?m=play&id='.$row['id'].'"><font size="2" color="black"> - '.$txt.'</a><br/>';
}

}
?>
 
<?php
$sym = 15; // на колко символа да реже
$query = mysql_query("SELECT * FROM songs top ORDER BY view DESC LIMIT 15");
while ($row = mysql_fetch_array($query))
{
$title = (strlen($row['title']) > $sym) ? substr($row['title'],0,$sym)."..." : $row['title'];
echo '<a href="index.php?m=play&id='.$row['id'].'"><font size="2" color="black"> - '.$row['artist'].'-'.$title.'..</a><br/>';

}
?>
 

Back
Горе