Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Pierwsze [xx] znaków zamiast całośći...
Forum PHP.pl > Forum > Gotowe rozwiązania
Qrzysio
Witam.


Używam systemu newsów Cutenews i dodatkowo skryptu który wyświetla ostatnie komentarze. Nie wiem jak zmienić poniższy skrypt żeby wyświetlał tylko np. 200 pierwszych znaków komentarza?
Bardzo proszę o pomoc.


[php:1:21fb06812f]<?php
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

//number of latest comments to show
if(!isset($comments_number)) $comments_number = 10;

//URL to where you include your news, example: http://site.com/news.php
$site_url = 'http://www.moja-ostroleka.pl/index.php';

//more help on the format: http://www.php.net/manual/en/function.date.php
$date_format = 'd.m.y, H:i';

//In your template you can use: {url}, {name}, {date}, {comment}, {ip}, {mail}, {newsid}, {comid}
$template = '<a class="ostatnie_komentarze" title="idĽ do tego komentarza" href="{url}"><I>napisał </i> <b>{name}</B><I> dnia {date}:</i> {comment}</a><br><br>';

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
END - END - END - END - END - END / don't edit below /
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

$latest_comments = array_fill(1, $comments_number, array('newsid'=>'0','comid'=>'0','name'=>'','mail'=>'','ip'=>'','comment'=>''));

function check_latest_comment($comment_line, $newsid){
global $latest_comments;
$tmp_latest_comments = $latest_comments;
$comment_arr = explode("|", $comment_line);
foreach($latest_comments as $key=>$latest_comment){

if($latest_comment['comid'] < $comment_arr[0]){

$previous = $latest_comments[$key];
foreach($latest_comments as $my_key=>$latest_comment_arr){
if($key < $my_key){
$current = $latest_comments[$my_key];
$latest_comments[$my_key] = $previous;
$previous = $current;
}
}

$latest_comments[$key] = array(
'newsid' => $newsid,
'comid' => $comment_arr[0],
'name' => $comment_arr[1],
'mail' => $comment_arr[2],
'ip' => $comment_arr[3],
'comment'=> $comment_arr[4],
);
}
}
}

$all_comments = file("cutenews/data/comments.txt");
foreach($all_comments as $comment_line)
{
$comment_line_arr = explode("|>|", $comment_line);
$newsid = $comment_line_arr[0];
$comment_arr = explode("||", $comment_line_arr[1]);
foreach($comment_arr as $single_comment)
{
check_latest_comment($single_comment, $newsid);
}
}


foreach($latest_comments as $comment){
$output = $template;
$output = str_replace("{url}", $site_url."?subaction=showcomments&id={newsid}#{comid}", $output);
$output = str_replace("{name}", $comment['name'], $output);
$output = str_replace("{mail}", $comment['mail'], $output);
$output = str_replace("{ip}", $comment['ip'], $output);
$output = str_replace("{comment}", $comment['comment'], $output);
$output = str_replace("{date}", date($date_format, $comment['comid']), $output);
$output = str_replace("{newsid}", $comment['newsid'], $output);
$output = str_replace("{comid}", $comment['comid'], $output);
echo $output;
}

?>[/php:1:21fb06812f]
BzikOS
[php:1:71dd4c2caa]<?php
$output = str_replace("{comment}", substr($comment['comment'], 0, 200), $output);
?>[/php:1:71dd4c2caa]
Qrzysio
Dzieki wielkie smile.gif Kombinowalem ale na to nie wpadlem ... Jeszcze raz dzieki smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.