Zadejte hledaný výraz...
Jakub Glos
Webtrh.cz
Vývoj webových stránek na WordPressu a proklientský přístup pro freelancery
Třídenní infromacemi nabitý prezenční + online kurz v Praze od Webtrhu pouze za 2 871 Kč
Více informací

Uprava f. – skratenie textu aj S HTML

monty
verified
rating uzivatele
1. 12. 2007 11:33:08
Pozrite si funkciu
http://php.vrana.cz/zkraceni-textu-s-xhtml-znackami.php
konkretne:
function html_cut($s, $limit)
A ono to skrati text na $limit aj pekne s HTML tagami, teda nebudu orezane alebo
nieco podobne...Je to super!
Len neviem ako tam mam zakonponovat, aby to orezalo od 100. znaku po 300. znak
(teda nie od O)
Chapete ze?
Ono ked v tom poslednom:
$s = substr($s, 0, $i);
zmenim tu 0 na ine tak to spravne nejde.
Dakujem velmi pekne
1. 12. 2007 11:33:08
https://webtrh.cz/diskuse/uprava-f-skratenie-textu-aj-s-html/#reply29632
function html_cut($s, $limit, $start = 0)
{
global $tags;
$skutecny_start = !empty($start) ? najdiPozici($s, $start) : 0;
$i = najdiPozici($s, $limit);
$s = substr($s, $skutecny_start, $i);
if ($tags) {
$s .= "";
}
return $s;
}
function najdiPozici($s, $limit) {
static $empty_tags = array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param');
$length = 0;
global $tags;
$tags = array(); // dosud neuzavřené značky
for ($i=0; $i < strlen($s) && $length < $limit; $i++) {
switch ($s{$i}) {
case '<':
// načtení značky
$start = $i+1;
while ($i < strlen($s) && $s{$i} != '>' && !ctype_space($s{$i})) {
$i++;
}
$tag = strtolower(substr($s, $start, $i - $start));
// přeskočení případných atributů
$in_quote = '';
while ($i < strlen($s) && ($in_quote || $s{$i} != '>')) {
if (($s{$i} == '"' || $s{$i} == "'") && !$in_quote) {
$in_quote = $s{$i};
} elseif ($in_quote == $s{$i}) {
$in_quote = '';
}
$i++;
}
if ($s{$start} == '/') { // uzavírací značka
$tags = array_slice($tags, array_search(substr($tag, 1), $tags) + 1);
} elseif ($s{$i-1} != '/' && !in_array($tag, $empty_tags)) { // otevírací značka
array_unshift($tags, $tag);
}
break;
case '&':
$length++;
while ($i < strlen($s) && $s{$i} != ';') {
$i++;
}
break;
default:
$length++;
}
}
return $i;
}
.
1. 12. 2007 11:55:03
https://webtrh.cz/diskuse/uprava-f-skratenie-textu-aj-s-html/#reply29631
monty
verified
rating uzivatele
1. 12. 2007 12:11:52
Fajn ide to, ale nejde to tak ako by som ja chcel ono, ja chcem aby naprt z
asdas
text uvodny ale ja budem chciet vypisat text konecny ale aj s tagom ktory este nebol uzavrtey
A ja chcem ked vypise konecny aby mi vypisalo:
text konecny ale aj s tagom ktory este nebol uzavrtey
Chapete asi ze? :)
Je to moc zlozite to takto dosiahnut??
1. 12. 2007 12:11:52
https://webtrh.cz/diskuse/uprava-f-skratenie-textu-aj-s-html/#reply29630
Pohrej si s proměnnou $tags a tím, co se s ní děje.
1. 12. 2007 12:29:14
https://webtrh.cz/diskuse/uprava-f-skratenie-textu-aj-s-html/#reply29629
monty
verified
rating uzivatele
1. 12. 2007 13:20:22
No hrajem sa s tym ale na nic nedochdzam..:((
Neporadil by si mi?
Uz zacinam byt zufaly.
Dakujem velmi pekne.
1. 12. 2007 13:20:22
https://webtrh.cz/diskuse/uprava-f-skratenie-textu-aj-s-html/#reply29628
Pro odpověď se přihlašte.
Přihlásit