small script problem...

Discussion in 'PHP' started by dotCEO, Sep 10, 2009.

  1. #1
    Hello,

    I really suck when it comes to programming, but I want to make a small update on the script I purchased.

    What Happens is that if the word is let's say more then 8 letters it'll DOT after 8. Example: Chocolate Bunny will be come Chocolat...

    I want to change it to <br /> after 10 letters... any help?

    Thanks in advanced... here is the snip

    function insert_cutText($array){
            $text = @$array["un"];
            $useDot == "" ? $useDot = true : $useDot = false ;
            $size == "" ? $size = 100 : $size = $size ;
            $dot = "";
            if ($useDot == "true"){$dot = "...";}
            if ((strlen($text)-1) <=  $size){
                $dot = "";
            }
            return substr($text,0,$size).$dot;
    	}
        
        function insert_removeBold($text){
        	$text = $text["un"];
        	$text = str_replace("<b>", "", "$text");
            $text = str_replace("<b>", "", "$text");
            return $text;
        }
    PHP:
     
    Last edited: Sep 10, 2009
    dotCEO, Sep 10, 2009 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    Try this

    
    
    function insert_cutText($array){
            $text = @$array["un"];
            $useDot == "" ? $useDot = true : $useDot = false ;
            $size == "" ? $size = 100 : $size = $size ;
            $dot = "";
            if ($useDot == "true"){$dot = "...";}
            if ((strlen($text)-1) <=  $size){
                $dot = "";
            }
            return substr($text,0,$size).$dot.'<br />';
        }
       
        function insert_removeBold($text){
            $text = $text["un"];
            $text = str_replace("<b>", "", "$text");
            $text = str_replace("<b>", "", "$text");
            return $text;
        }
    
    PHP:
     
    stephan2307, Sep 11, 2009 IP
  3. dotCEO

    dotCEO Member

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #3
    no, that didn't really work...

    Bascailly what I want this little snip to do is instread of Chocolate Bunny To turn to Chocolat...
    To be:
    Chocolat
    e Bunny


    Thanks for your help
     
    dotCEO, Sep 11, 2009 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    You mean like this one?

    
    function insert_cutText($array){
             $text = @$array["un"];
    
            $newtext = '';
            $counter = 0;
            while ( strlen($text) > 0) {
                if ($counter > 0 ) {
                    $newtext .= '<br />';
                }
                $temp = substr($text,8);
                echo $temp;
                $newtext .= substr($text,0,8);
                $text=$temp;
                $counter++;
            }
    
            return $newtext;
        }
    
    PHP:
     
    stephan2307, Sep 11, 2009 IP
  5. dotCEO

    dotCEO Member

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #5
    that seems to be correct, but for some reason when I put it in there, the page goes blank.... don't know what I'm doing wrong :S
     
    dotCEO, Sep 11, 2009 IP
  6. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #6
    try this one.

    
    function insert_cutText($array){
             $text = @$array["un"];
    
            $newtext = '';
            $counter = 0;
            while ( strlen($text) > 0) {
                if ($counter > 0 ) {
                    $newtext .= '<br />';
                }
                $temp = substr($text,8);
                $newtext .= substr($text,0,8);
                $text=$temp;
                $counter++;
            }
    
            return $newtext;
        }
    
    
    PHP:
     
    stephan2307, Sep 11, 2009 IP
  7. dotCEO

    dotCEO Member

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #7
    that did it brother! Thanks 1,000,000

    Let me know if I can help you with anything ever :)
     
    dotCEO, Sep 11, 2009 IP
  8. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #8
    No problem.
     
    stephan2307, Sep 11, 2009 IP