hi i would like to know on how to display limit content without destroying the html tags or lacking any..
i know how to substr works and i always use it to display limit but when i try to limit for ex. 50 letters then in the content there is a html tag and the closing tags is out of 50 of course you will see some abnormalities on the content. so i want to know if how i could fix it....
I think this is not at possible but without example of html I don't want to say this 100%.
Sonam
"Display limit content"? Can you clarify what you mean by this? I assume you mean "display limited content" - limited in what way though?
for ex.. you have a html formatted text
Duis viverra porttitor mauris? In interdum luctus quam. Nam ac nulla ac <div>diam vulputate posuere. Nunc ac arcu non ipsum tristique commodo.</div> <span>Vivamus auctor</span> laoreet massa. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce quis risus non augue venenatis condimentum.<strong>hello world</strong>
this is stored on the database.
now when i try to display this content and limit it like
| Code: |
echo substr("content above",0,100);
|
but what i want is when i want to limit to display the content, i don't want to end up with an open tag in the middle of it let say, if there is a "<div>" tag belongs before 100 words. i want to end up the display content after the last closing tags.
IF html tags don't play visual part n ur application then you don't need to play on tags just limit content itself if possible.
| Code: |
<tag>LIMIT("Title of the message",50)</tag>
<tag>LIMIT("Content of the message. Content of the message. Content of the message.",200)</tag> |
or you could make a list of all the tags, then limit the text and search for tags. If any open tags are found but no closing tags make it add the closing tags in the end.
yes, but that's what i'm trying because, you don't know what is the lacking tag within the content, let say it lacks <span> and <div> tags or <li> tags, that is why i'm trying to figure out how it will be. Anyway thanks to @sonam i'll try the link you had given..
don't you think you could do something with preg_match? That should be able to search for html tags and see if they are closed properly.
| Quote: |
| yes, but that's what i'm trying because, you don't know what is the lacking tag within the content, let say it lacks <span> and <div> tags or <li> tags, that is why i'm trying to figure out how it will be. Anyway thanks to @sonam i'll try the link you had given. |
Maybe is, in that case, better solution to use iframe or object tag, with fixed width and height and display like block on the page.
Sonam
Hi there, did you mean that you have a string of text which is formatted but you can't use substr() because it will also cut off your HTML tags?
What about trying to separate content with formatting? E.G.
| Code: |
<?php
$txt_string = "This is a text";
$new_txt = substr($txt_string);
echo "<b>$new_txt</b>";
?> |
I think this is what you're trying to ask?
However if the problem is because the text is already processed with HTML tags before being subtracted then during the $_GET or $_POST method that (I assume) you are using to transfer the content. Filter the text first.
http://domain.com/process.php?rawtext=This+is+a+text
The domain above is an example how the text would be passed on from a previous page whereby the text is filtered.
| Code: |
<?php
$source = "<b>This is a text</b>";
$process_txt = strip_tags($source);
echo "<form method=\"get\" action=\"process.php?rawtext=$process_text\"><textarea name=\"send_text\">$process_txt</textarea></form>";
?> |
In the process.php page it will be retrieved like this...
| Code: |
<?php
$get_rawtext = $_GET["rawtext"];
echo "<b>$get_rawtext</b>";
|
Hope it helps 