Re: Read more link with HTML code
| From: | Chris | Date: | Tue, 08 May 2007 07:31:14 +0000 |
| Subject: | Re: Read more link with HTML code | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-43566@lists.php.net to get a copy of this message | ||
Chris wrote:
Mike van Hoof wrote:Actually that's not going to work at all. You'd have to do something like: $open_tags = array('<b>', '<i>', '<u>'); $close_tags = array('</b>', '</i>', '</u>'); foreach ($open_tags as $p => $tag) { $open_count = substr_count($string, $tag); $close_count = substr_count($string, $close_tags[$p]); if ($open_count != $close_count) { echo "Mismatch for tag " . htmlentities($tag) . "<br/>"; } } -- Postgresql & php tutorials http://www.designmagick.com/Hello list, I got a problem with displaying content in a "read more block" which contains HTML code. The problem is as followes: I got a large piece of content, which contains HTML code (<b><u><i> etc), but after 200 characters a read more link appears. At the moment I strip al the HTML out of this piece of content, and display the full set off content on another page. But now i also want to display the bold text etc. in the first (200 chrs) content block. The only problem i have here, is that when I got a bold tag opend in the first 200 chrs, and it's closed after 400 chrs, then the rest off the page is also bold.You could try using http://php.net/substr_count and do something like: $tags = array('<b>', '<i>', '<u>'); foreach ($tags as $p => $tag) { $count = substr_count($string, $tag); if ($count % 2 != 0) {echo "Found a mismatch for tag " . htmlentities($tag) . "<br/>";} } Not a great solution because you're hardcoding the tags you're looking for but there aren't that many that change text appearances like these do (but then again this method won't work for <span or <div tags because you can place styles inside those tags).... Unless you want to get into regex'es....