Kiro Kiro - 15 days ago 6
MySQL Question

How to make limit text lenght in php with mysql

I have some text in database. By using substr() I made letter limit, but it's not working I and dont know why. Plus, some letters like "č,š,ě,..." transform to wierd pictures, how I allow this letters?

<?php
if (empty($_GET["p"])) {
$sql = "SELECT * FROM WEB_ARTICLE ORDER BY ID DESC LIMIT $start, 4";
$data = $db->query($sql);

foreach ($data as $value) {
$SUBSTRING = substr($value["Clanek"], 0, 260)."...";

echo "<div class='nadpisarticles'><b>".$value["ID"].". ".'<a href="websitearticles.php?p='.$value["ID"].'">'.$value["Nazev"].'</a>'."</b></div>"."<div class='textarticles'><p class='break'>".$SUBSTRING."</p><br>".$value["Cas"]."<br><br><br>"."</div>";
}
?>

Answer

you could use:

$rest = substr("clankyx", 0, -1);  // returns "clanky"

check out: http://php.net/manual/en/function.substr.php

or u can check out mysql SELECT SUBSTRING function

http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_substring