Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
alien13
New Member
New Member



Joined: Jan 29, 2005
Posts: 5

PostPosted: Sat Jan 29, 2005 2:27 am Reply with quote

I made a block in which the titles of the last 11 news articles are being loaded. Because some of the titles are too long. I was wondering how to make all which are longer than 38 symbols to end with "...".

For example:

Splinter Cell: Chaos Theory - Мultiplayer

and

Splinter Cell: Chaos Theory - Мultipl...

I managed reach to a point where I could make the "..." appear after each of the titles, but this doesnt serve my purpose, because I want the "..." to appear only after titles longer than 38 symbols. Thanks in advance!

Code:
<? 

if (eregi("block-pszone.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

global $prefix, $dbi;

$count_letters = 38;

$content .= "<table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
      <td width=\"295\"><table width=\"295\" height=\"5\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
            <td><img src=\"http://opit.jpg\" border=\"1\"></td>
  </tr>
</table></td>
      <td width=\"5\" height=\"222\"> </td>
      <td width=\"250\" height=\"222\"><table width=\"250\" height=\"222\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
        <tr>
          <td height=\"22\" class=\"row6\">News</td>
        </tr>
        <tr>
    <td class=\"row5\" valign=\"top\" height=\"100%\">";
$a = 1;
$result = sql_query("select title, counter, sid FROM ".$prefix."_stories WHERE topic = '1' order by sid DESC limit 0,11", $dbi);
while(list($title, $counter, $sid) = sql_fetch_row($result, $dbi)) {

$perem1 = stripslashes($title);
$perem2 = substr($perem1, 0, $count_letters) . "...";
$content .= "<a href=\"modules.php?name=News&amp;file=article&amp;sid=$sid\">$perem2</a><br>";
}
$content .= "  </td>
        </tr>
      </table></td>
    </tr>
  </table>
<table width=\"550\" height=\"5\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
    <td></td>
  </tr>
</table>";

?>
 
View user's profile Send private message
Nukeum66
Life Cycles Becoming CPU Cycles



Joined: Jul 30, 2003
Posts: 551
Location: Neurotic, State, USA

PostPosted: Sat Jan 29, 2005 7:46 am Reply with quote

Try This:
Code:
Saving Forum space removed old code post

_________________
Scott Johnson MIS Ubuntu/Linux 11.10

Last edited by Nukeum66 on Sat Jan 29, 2005 8:58 am; edited 3 times in total 
View user's profile Send private message Visit poster's website
sixonetonoffun
Spouse Contemplates Divorce



Joined: Jan 02, 2003
Posts: 2496

PostPosted: Sat Jan 29, 2005 7:48 am Reply with quote

This is from the php.net user notes I changed the name to prevent conflict. If your using it on more then one block you might want to add it to the mainfile.php so you don't have to duplicate the function. Use like this:
$perem1=rDots($perem1);
It could be tweaked to take the last to arguements on the fly but this should get you started.

Code:


    function rDots($str, $len = 38, $dots = "...") {
        if (strlen($str) > $len) {
            $str = explode(".", $str);
            $dotlen = strlen($dots);
            $str = substr_replace($str[0].$str[1].$str[2].$str[3].$str[4], $dots, $len - $dotlen);
        }
        return $str;
    }

_________________
[b][size=5]openSUSE 11.4-x86 | Linux 2.6.37.1-1.2desktop i686 | KDE: 4.6.41>=4.7 | XFCE 4.8 | AMD Athlon(tm) XP 3000+ | MSI K7N2 Delta-L | 3GB Black Diamond DDR
| GeForce 6200@433Mhz 512MB | Xorg 1.9.3 | NVIDIA 270.30[/size:2b8 
View user's profile Send private message
alien13







PostPosted: Sat Jan 29, 2005 8:27 am Reply with quote

First, thank you, for fast answer and sorry for bad english!

Nukeum66, the code didn't change anything.

sixonetonoffun, sorry but I can't understand. What I must to change in the block? How must look like?
 
Nukeum66







PostPosted: Sat Jan 29, 2005 8:30 am Reply with quote

I have edited the above code as I made a BOO BOO in the first. Your block works fine, I tested it on my site.... Wink
 
Nukeum66







PostPosted: Sat Jan 29, 2005 8:33 am Reply with quote

Bottom center look [ Only registered users can see links on this board! Get registered or login! ]
 
alien13







PostPosted: Sat Jan 29, 2005 8:41 am Reply with quote

I want the "..." to appear only after titles longer than 38 symbols. Thanks for a try anyway Smile
 
Nukeum66







PostPosted: Sat Jan 29, 2005 8:50 am Reply with quote

OH Sorry I made another BOO BOO.... Laughing

Here use this:
Code:
<?

if (eregi("block-pszone.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

global $prefix, $dbi;

function t2_string($str)
{
   $tlength = 38; // EDIT LENGTH OF TITLE

   if (strlen($str) > $tlength)
      return substr($str, 0, $tlength)."... ";
   else
      return $str;
}

$content .= "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
      <td width=\"295\"><table width=\"295\" height=\"5\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
            <td><img src=\"images/topics/news.gif\" border=\"1\"></td>
  </tr>
</table></td>
      <td width=\"5\" height=\"222\"> </td>
      <td width=\"250\" height=\"222\"><table width=\"250\" height=\"222\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
        <tr>
          <td height=\"22\" class=\"row6\">News</td>
        </tr>
        <tr>
    <td class=\"row5\" valign=\"top\" height=\"100%\">";
$a = 1;
$result = sql_query("select title, counter, sid FROM ".$prefix."_stories WHERE topic = '1' order by sid DESC limit 0,11", $dbi);
while(list($title, $counter, $sid) = sql_fetch_row($result, $dbi)) {

$content .= "<a href=\"modules.php?name=News&amp;file=article&amp;sid=$sid\">". t2_string($title) ."</a><br>";
}
$content .= "</td>
        </tr>
      </table></td>
    </tr>
  </table>
<table width=\"100%\" height=\"5\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
    <td></td>
  </tr>
</table>";

?>
 
sixonetonoffun







PostPosted: Sat Jan 29, 2005 8:51 am Reply with quote

Exactly like nukeum posted just switch the function he used to use the one I posted. That will only add the dots to titles longer then 38 chars.
 
sixonetonoffun







PostPosted: Sat Jan 29, 2005 8:57 am Reply with quote

LMAO! Uploading with ftp its taking so long for my responses to go threw yer beating me every time Nukeum!
 
Nukeum66







PostPosted: Sat Jan 29, 2005 9:00 am Reply with quote

I had a lot of coffee this morning
 
alien13







PostPosted: Sat Jan 29, 2005 9:22 am Reply with quote

It works! I realy thanks!
 
alien13







PostPosted: Mon Feb 07, 2005 2:08 am Reply with quote

I have another question. It is posible to load a HTML file in the same block - something like that:

<?
if (eregi("block-pszone.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}

global $prefix, $dbi;

function t2_string($str)
{
$tlength = 38; // EDIT LENGTH OF TITLE

if (strlen($str) > $tlength)
return substr($str, 0, $tlength)."... ";
else
return $str;
}

$content .= "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td width=\"295\"><table width=\"295\" height=\"5\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td><img src=\"images/topics/news.gif\" border=\"1\"></td>
</tr>
</table></td>
<td width=\"5\" height=\"222\"> </td>
<td width=\"250\" height=\"222\"><table width=\"250\" height=\"222\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td height=\"22\" class=\"row6\">News</td>
</tr>
<tr>
<td class=\"row5\" valign=\"top\" height=\"100%\">";
$a = 1;
$result = sql_query("select title, counter, sid FROM ".$prefix."_stories WHERE topic = '1' order by sid DESC limit 0,11", $dbi);
while(list($title, $counter, $sid) = sql_fetch_row($result, $dbi)) {

$content .= "<a href=\"modules.php?name=News&amp;file=article&amp;sid=$sid\">". t2_string($title) ."</a><br>";
}
$content .= "</td>
</tr>
</table></td>
</tr>
</table>
<table width=\"100%\" height=\"5\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td></td>
</tr>
</table><br><table width=\"100%\" border=\"0\">
<tr>
<td>hier I want to load HTML - [ Only registered users can see links on this board! Get registered or login! ]</td>
</tr>
</table>";

?>
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©