/ Published in: PHP

suppose you have some html-formatted text of which you would like to show the first 45 characters.
This function closes any tags that are not-closed because of cutting the first 45 characters.
Note that tags are also counted when defining the first 45 characters!
This function closes any tags that are not-closed because of cutting the first 45 characters.
Note that tags are also counted when defining the first 45 characters!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function closetags ( $html ) { #put all opened tags into an array $openedtags = $result[1]; #put all closed tags into an array $closedtags = $result[1]; # all tags are closed { return $html; } # close tags for( $i = 0; $i < $len_opened; $i++ ) { { $html .= "</" . $openedtags[$i] . ">"; } else { } } return $html; } $str = "<div>This is some interesting <strong><em>content!</em> And this</strong> line is <em>"; $str .= "abundantly</em> formatted</div>"; $x = closetags ( $snippet ); ?>
Comments
