Re: Read more link with HTML code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mike van Hoof wrote:
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....

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux