Trimming and stripping

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

Trimming and stripping

Post by kevrelland »

Hi, i want to strip the tags from this database return as well as limit the number of characters returned.

Code: Select all

<p><?php echo strip_tags($row_archive['archive_content'], '<a>') ?></p>
I have got this and and it strips the tags perfectly but i have no idea on how to combine the trim with it

Code: Select all

<p><?php echo TrimByLength($row_archive['archive_content'], 200, false); ?></p>
Which trims the length beautifully
Can you guys help me out
Cheers
Kev
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: Trimming and stripping

Post by dejvos »

What about this:

Code: Select all

<?php
$x = strip_tags($row_archive['archive_content'], '<a>');
echo TrimByLength($x, 200, false);
?>
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

Re: Trimming and stripping

Post by kevrelland »

Thanks, perfect.
i'm stuck at work without my book, and was having a brain melt down and just couldn't think
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Trimming and stripping

Post by pickle »

I'm not sure what your TrimByLength() function does, but you may be able to use substr() instead.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trimming and stripping

Post by AbraCadaver »

Code: Select all

<p><?php  echo TrimByLength(strip_tags($row_archive['archive_content']), 200, false); ?></p>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply