Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    Funzione per accorciare testo

    Ciao!

    Mettiamo che io abbia una stringa di 35 caratteri-. Volgio fare in modo he questa stringa essendo maggiore di 27 caratteri venga tagliata (la parte finale) e vengano inseriti alla fine "..."


    Possibile? Grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2004
    Messaggi
    483
    Prova a guardare questo link preso dalle pillole LINK


    L'unica cosa è che questa funziona lavora sul numero di parole e non sul numero di caratteri...


    Altrimenti per tagliare una stringa dopo tot caratteri c'è la funzione substr LINK

    Ciao!

  3. #3
    Io ho sempre usato substr come detto sopra.

    Codice PHP:
    $troncata = (strlen($stringa) > 27) ? substr($stringa,0,27)."..." $stringa 

  4. #4
    Grazie: ma con questo codice:

    Codice PHP:
    $ciao="blsklsjsjvdffjdwsjdsndscnsdcnjsdcnjosdnijcnijdn ded edfew ferw";
    if (
    strlen($ciao)>20){
    $oksubstr($ciao,0,27)."...";

    echo 
    $ok

    ottengo:


    blsklsjsjvdffjdwsjdsndscnsd...blsklsjsjvdffjdwsjds ndscnsd...blsklsjsjvdffjdwsjdsndscnsd...blsklsjsjv dffjdwsjdsndscnsd...

    Perchè? a me interessa che non venga ripetuto il nome del file...

  5. #5
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    Originariamente inviato da Giggius89
    Grazie: ma con questo codice:

    Codice PHP:
    $ciao="blsklsjsjvdffjdwsjdsndscnsdcnjsdcnjosdnijcnijdn ded edfew ferw";
    if (
    strlen($ciao)>20){
    $oksubstr($ciao,0,27)."...";

    echo 
    $ok

    ottengo:


    blsklsjsjvdffjdwsjdsndscnsd...blsklsjsjvdffjdwsjds ndscnsd...blsklsjsjvdffjdwsjdsndscnsd...blsklsjsjv dffjdwsjdsndscnsd...

    Perchè? a me interessa che non venga ripetuto il nome del file...
    probabilmente hai inserito il controllo in un ciclo for e foreach... mi spieghi quella { che vedo aperta nella riga if e non chiusa?
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  6. #6
    no tranquillo, la parentesi non è chiusa perchè ho preso solo una porzione di codice...cavolo...hai ragione...non ho la più pallida idea di come modificare 'sto script allora...se qualche buon' anima puo' provare...Ditemi che posto il codice

  7. #7
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    posta piu codice, magari la ripetizione è dovuta ad un altro fattore l' intero contesto in cui si trova ...
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  8. #8
    Codice PHP:
    <?php

    /*
    * DOCMan 1.3.0 for Mambo 4.5.1 CMS  
    * @version $Id: mod_docman_lister.php,v 1.3 2005/08/09 02:40:00 johanjanssens Exp $
    * @package DOCMan_1.3.0
    * @copyright (C) 2003 - 2005 The DOCMan Development Team
    * @license [url]http://www.gnu.org/copyleft/gpl.html[/url] GNU/GPL
    * Official website: [url]http://www.mambodocman.com/[/url]
    */

    // you can define the following parameters at administration:

    // show_icon = displays a generic icon near the name of the document, using the theme defined (default = 1) No=0; Yes=1
    // show_counter = displays the number of downloads (default = 1) No=0; Yes=1
    // show_category = display the category name after the document name (default = 1) No=0; Yes=1
    // link_type = the type of link to display (default = 0) List=0; Search=1; Details=2; Direct=3
    // moduleclass_sfx = module class suffix (default='')
    // show_list = show results using <ul> tag (default = 0) No=0; Yes=1
    // text_pfx = text to show before list (default='')
    // text_sfx = text to show after list (default='')
    // limits = number of downloads to display (default = '') 
    // cat_limit = search a specific category ( or list ) if provided (default='')
    // itid = override the passed itemid and use this one, if present (default='')
    // order_by = how to order the results (default = 0) Most hits=0; Least hits=1; Newest=2;
    //            oldest=3; Alphabet=4; Alphabet, reverse=5

    // Internal revision 1 - 27 march 2005
    // Internal revision 2 - 27 march 2005 - fixed bugs
    // Internal revision 3 - 27 march 2005 - added moduleclass_sfx and cache, output fix
    // Internal revision 4 - 27 march 2005 - added text prefix and suffix
    // Internal revision 5 - 27 march 2005 - cosmetic fixes
    // Internal revision 6 - 17 april 2005 - moved language strings, made compatible with 1.3 RC 1
    // Internal revision 7 - 08 aug   2005 - made compatible with 1.3 RC 2

    // TODO - Ben Jones 2005
    // Seperators/titles on admin parameters section would be nice
    // CSS classes should be merged with main DOCMan ones? maybe not?
    // Make admin help button work

    // Check we're called from the right place
    defined'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
    // Include the DOCMan class
    include_once( $mosConfig_absolute_path."/administrator/components/com_docman/docman.class.php");

    //DOCMan core interaction API
    global $_DOCMAN;
    if(!
    is_object($_DOCMAN)) {
        
    $_DOCMAN = new dmMainFrame();
    }

    $_DOCMAN->setType(_DM_TYPE_MODULE);
    $_DOCMAN->loadLanguage('modules');

    // Include some other DOCMan classes
    require_once($_DOCMAN->getPath('classes''utils'));
    require_once(
    $_DOCMAN->getPath('classes''file'));
    require_once(
    $_DOCMAN->getPath('classes''model'));

    // get the parameters
    $show_icon          abs($params->def'show_icon'));
    $show_counter     abs($params->def'show_counter'));
    $show_category      abs($params->def'show_category'));
    $link_type        abs($params->def'link_type'));
    $moduleclass_sfx $params->get'moduleclass_sfx' );
    $show_list        abs($params->def'show_list'));
    $text_pfx          $params->def'text_pfx''' );
    $text_sfx          $params->def'text_sfx''' );
    $limits           $params->def'limits''' );
    $cat_limit          $params->def'cat_limit''' );
    $itid               $params->def'itid''' );
    $order_by        abs($params->def'order_by'));

    $menuid $_DOCMAN->getMenuId();
    $user   $_DOCMAN->getUser(); 

    // Some strings
    $string_icon_alt "File icon";
    $class_link     "mod_docman_lister_link" $moduleclass_sfx;
    $class_prefix     "mod_docman_lister_prefix" $moduleclass_sfx;
    $class_suffix     "mod_docman_lister_suffix" $moduleclass_sfx;

    // Setup some variables
    $content "";

    // Sort out the ordering
    switch ( $order_by ) {
        case 
    0:
            
    // Most hits
            
    $order "hits";
            
    $dir   "DESC";
            break;   
        case 
    1:
            
    // Least hits
            
    $order "hits";
            
    $dir   "ASC";
            break;   
        case 
    2:
            
    // Newest
            
    $order "date";
            
    $dir   "DESC";
            break;   
        case 
    3:
            
    // Oldest
            
    $order "date";
            
    $dir   "ASC";
            break;   
        case 
    4:
            
    // Alphabetically
            
    $order "name";
            
    $dir   "ASC";
            break;   
        case 
    5:
            
    // Alphabetically, reverse
            
    $order "name";
            
    $dir   "DESC";
            break;   
    }

    $rows DOCMAN_Docs::getDocsByUserAccess($cat_limit$order$dir$limits); 

    // If we have a textual prefix, show it now
    if ( strlen($text_pfx) > ) {
        
    $content .= "<span class='$class_prefix'>" $text_pfx "</span>
    "
    ;   
    }

    // List output
    if ( $show_list == ) {
        
    $content .= "<ul>";   
    }

    // For each row of our result..
    foreach ($rows as $row) {
        
        
    // List output
        
    if ( $show_list == ) {
            
    $content .= "[*]";   
        }

        
    // Create a new document
        
    $doc = new DOCMAN_Document($row->id);
        
        
    // Create the appropriate type of link
        
    $linkText "";
        switch (
    $link_type) {
            case 
    0:
                
    $linkText "index.php?option=com_docman&task=cat_view&amp;Itemid=$menuid&amp;gid=".$row->catid."&amp;orderby=dmdatecounter&ascdesc=DESC";
                break;
            case 
    1:
                
    $linkText "index.php?option=com_docman&amp;task=search_result&amp;Itemid=$menuid&amp;search_phrase=" urlencode($row->dmname) . "&amp;search_mode=phrase";
                break;
            case 
    2:
                
    $linkText "index.php?option=com_docman&amp;task=doc_details&amp;Itemid=$menuid&amp;gid=" $row->id;
                break;
            case 
    3:
                
    $linkText "index.php?option=com_docman&amp;Itemid=$menuid&amp;task=doc_download" $itid "&amp;gid=" $row->id;
                break;   
        }
        
    $url sefRelToAbs$linkText );
        
    $content .= "<a class=\"$class_link\" href=\"$url\">";
       
        
    // If we are showing the icon, do it
        
    if ($show_icon) {
            
    $content .= "<img border='0' src=\"".$doc->getPath('icon'1'16x16')."\" alt=\""_DML_FILEICON_ALT ."\" /> ";
        }
        
        
    // Output the document name
       
    $content .= $doc->getData('dmname');



         


        
    // If we are showing the counter or the category, do it
        
    if ($show_counter) {
            
    $content .= " (".$doc->getData('dmcounter').")";
        }
        if (
    $show_category) {
            
    $content .= "
    ("
    .$row->cat_title.")";
        }
            
        
    // Add the end link and break
        
    $content .= "</a>";

        
    // List output
        
    if ( $show_list == ) {
            
    $content .= "";   
        } else {
            
    $content .= "
    "
    ;
        }

    }

    // If we had 0 results.. 
    if ( count($rows) == ) {
        
    // List output
        
    if ( $show_list == ) {
            
    $content .= "[*]";   
        }
        
        
    $content .= _DML_MOD_NODOCUMENTS ;

        
    // List output
        
    if ( $show_list == ) {
            
    $content .= "";   
        }
    }

    // List output
    if ( $show_list == ) {
        
    $content .= "[/list]" ;   
    }

    // If we have a textual suffix, show it now
    if ( strlen($text_sfx) > ) {
        
    $content .= "<span class='$class_suffix'>" $text_sfx "</span>
    "
    ;   
    }

    ?>

    E' uno script di un modulo di Joomla che serve per mostrare gli ultimi downloads. A me interessa che il nome del file , se più lungo di circa 27 caratteri, venga troncato a tre caratteri prima dei 27 ed aggiunti... ( in modo che non venga scritto su due righe...)

    Questa porzione stampa il nome:

    // Output the document name

    $content .= $doc->getData('dmname');


    Grazie mille!!!

  9. #9

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.