News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

SSI.php modification to remove URL's.

Started by DuckFat, April 25, 2006, 12:54:01 PM

Previous topic - Next topic

DuckFat

Can anyone tell me how to modify the ssi_boardNews function to either eliminate long URL's or truncate them to a certain length and append "..."?  The latter solution would be best but just deleting any words or URL's longer than 25 characters would work for my needs.  I've tried various preg_replace commands but I can't seem to figure it out being a relative PHP newbie.

Thanks for any assistance you can give.
-- DuckFat


B Patterson

foreach ($return as $news)
{
echo '
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
<div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</div>

<div class="post" style="padding: 2ex 0;">', $news['body'], '</div>

', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
</div>';

if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}

Well, there's the general output of the links and stuff... what exactly do you want modified?  Which link?

DuckFat

Ideally, I want any displayed URL or any text string longer than 25 characters in the title or body of the message to be truncated to 22 characters with "..." added at the end.  Alternatively, I'd like to just eliminate anything longer than 25 characters from the output.  Thank you.
-- DuckFat


gog

The beaty of the SSI.php is that it can return arrays of data, instead of HTML outpust. You can tell the function to return an array, then you can use PHP's substr() function to use first N charasters of every string...

B Patterson

#4
So then it becomes:

function truncate($text, $length=25)
{
$trunc = (strlen($text)>$length)?true:false;

if($trunc)
return substr($text, 0, $length).'...';
else
return $text;
}
foreach ($return as $news)
{
echo '
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', truncate($news['subject']), '</b>
<div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</div>

<div class="post" style="padding: 2ex 0;">', truncate($news['body']), '</div>

', $news['link'], $news['locked'] ? '' : ' | ', $news['comment_link'], '
</div>';

if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}

It takes some testing, but it should work....

[EDIT]
Okay, so I updated the code, tested, and it works as expected: Viewable Here

DuckFat

THANK YOU!  This works the way I want it to now.
-- DuckFat


B Patterson


Advertisement: