Author |
Message |
alien13
New Member


Joined: Jan 29, 2005
Posts: 5
|
Posted:
Sat Jan 29, 2005 2:27 am |
|
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&file=article&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>";
?>
|
|
|
|
|
 |
Nukeum66
Life Cycles Becoming CPU Cycles

Joined: Jul 30, 2003
Posts: 551
Location: Neurotic, State, USA
|
Posted:
Sat Jan 29, 2005 7:46 am |
|
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 |
|
|
 |
sixonetonoffun
Spouse Contemplates Divorce

Joined: Jan 02, 2003
Posts: 2496
|
Posted:
Sat Jan 29, 2005 7:48 am |
|
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 |
|
|
 |
alien13

|
Posted:
Sat Jan 29, 2005 8:27 am |
|
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

|
Posted:
Sat Jan 29, 2005 8:30 am |
|
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....  |
|
|
|
 |
Nukeum66

|
Posted:
Sat Jan 29, 2005 8:33 am |
|
|
|
 |
alien13

|
Posted:
Sat Jan 29, 2005 8:41 am |
|
I want the "..." to appear only after titles longer than 38 symbols. Thanks for a try anyway  |
|
|
|
 |
Nukeum66

|
Posted:
Sat Jan 29, 2005 8:50 am |
|
OH Sorry I made another BOO BOO....
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&file=article&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

|
Posted:
Sat Jan 29, 2005 8:51 am |
|
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

|
Posted:
Sat Jan 29, 2005 8:57 am |
|
LMAO! Uploading with ftp its taking so long for my responses to go threw yer beating me every time Nukeum! |
|
|
|
 |
Nukeum66

|
Posted:
Sat Jan 29, 2005 9:00 am |
|
I had a lot of coffee this morning |
|
|
|
 |
alien13

|
Posted:
Sat Jan 29, 2005 9:22 am |
|
It works! I realy thanks! |
|
|
|
 |
alien13

|
Posted:
Mon Feb 07, 2005 2:08 am |
|
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&file=article&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 - http://mysite.com/index3.htm</td>
</tr>
</table>";
?> |
|
|
|
 |
|