raplace text/url with dots after 20 letters [....]

Discussion in 'PHP' started by cornetofreak, May 12, 2008.

  1. #1
    i have a piece of code that collects url from a database then i con call this in another file but i would like to replace the text after 20 letters the several dots here is the code

    		
    //print_r($row);
    $info['results'][$num]['number']=$num+1;
    $info['results'][$num]['url']=$row[0];
    $info['results'][$num]['title']=$row[1];
    $info['results'][$num]['type']=$row[2];
    if($row[3]) $info['results'][$num]['filesize']=", FileSize: ".$row[3]; //number_format($row[3],0,"."," ");
    		else $info['results'][$num]['filesize']="<font color=\"grey\"> Not Checked</font>";
    		if($row[5])
    		{
    			if(strpos($row[5],"http://")!==false) $info['results'][$num]['source']=" <a href=\"".$row[5]."\" target=\"_blank\"><img src=\"templates/padlock.gif\"style=\"border-style: none\" alt=\"Source\" width=\"64\" height=\"16\" /></a>";
    			else $info['results'][$num]['source']=" (<a href=\"http://".$row[5]."\" target=\"_blank\">source</a>)";
    		}
    		else 				$info['results'][$num]['source']=""; <-- think its this line
    		$info['results'][$num]['relevance']=$row[4];
    
    		$substr=strtolower(substr($info['results'][$num]['url'],-20));
    		foreach($icons as $key => $value)
    PHP:

     
    cornetofreak, May 12, 2008 IP
  2. seo8k

    seo8k Guest

    Messages:
    70
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    change this
    $substr=strtolower(substr($info['results'][$num]['url'],-20));
    to
    $substr=strtolower(substr($info['results'][$num]['url'],20));
     
    seo8k, May 12, 2008 IP
  3. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    naope it not doing anything
     
    cornetofreak, May 13, 2008 IP
  4. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    For sanities sakes, I'll just use placeholders...
    
    // our string
    $string = $myarray['location1'];
    // start at position 0 and continue until position 20
    $string = substr($string, 0, 20);
    // lower everything
    $string = strtolower($string);
    
    // all in one - harder to debug
    $string = strtolower(substr($string, 0, 20))."...";
    
    Code (markup):
     
    Altari, May 13, 2008 IP
  5. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    that aint workin aswell i cant clock on myself :mad:
     
    cornetofreak, May 13, 2008 IP
  6. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    What is it doing, not doing, etc? Errors, samples?
     
    Altari, May 13, 2008 IP
  7. msaqibansari

    msaqibansari Peon

    Messages:
    84
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    <style type="text/css">
    .mydiv
    {
    	height: 20px;
    	width: 150px;
    	overflow:hidden;
            text-overflow: ellipse;
    }
    </style>
    
    <div class="mydiv">This is long text. This is long text. This is long text. This is long text.</div>
    
    Code (markup):
     
    msaqibansari, May 13, 2008 IP
  8. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    
    <?php
    
    echo substr($string,0,20)."...";
    ?>
    
    PHP:
    didnt realize everyone else said to use substr
     
    bobb1589, May 14, 2008 IP