Display first two hundred characters, ignoring HTML markup
Posted: Wed Jul 12, 2006 4:18 am
Pimptastic | Please use
The only possibility I see is going through the $newsitem, character by character to build up $newsdisplay. Upon encountering a '<' the building of the $newsdisplay string stops, while the reading of $newsitem continues. Once a '>' is encountered the build-up of $newsdisplay continues.
To mee this seems very elaborate as and a novice PHP user, I may not be aware of a smarter way of doing this.
I appreciate any suggestion you may have in tackling this issue.
Thanks,
Frits
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I have been searching on the forum but could not find the answer to the following:
I have a number of newsitems, which I retrieve from a database. For each newsitem I want to display a teaser on the front page of the site. The teaser should be limited to a maximum length (200 characters). However, the newsitem as retrieved from the database may contain HTML (e.g. <strong> or <br/> or <a link....> etc). In counting the characters, this markup should be ignored.
Example, the following string may be retrieved from the database:
This is the <strong>latest</strong> newssample.
The string should count as 26, not as 43.
The structure is something like:Code: Select all
$maxlength=200
if strlen($newsitem>$maxlength) {
*** code for limiting text to maximum length, excluding markup ***
$newsdisplay =$newsdisplay.'. . .'; }
else {
$newsdisplay =$newsitem ;
}
echo($newsdisplay);To mee this seems very elaborate as and a novice PHP user, I may not be aware of a smarter way of doing this.
I appreciate any suggestion you may have in tackling this issue.
Thanks,
Frits
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]