Handling layout breaking text #2
This is a follow-up post to the previous one. I have made some modifications so that you can have HTML tags in your text and my code will still work. I’ve packed the whole thing in a PHP5 class which you can get here. I wanted to put a demo up, but apparently I don’t have PHP5 support here, and Mb_* functions seem to be a mystery to GoDaddy also, so no demo…
So how did I solve the problem with HTML tags? Well before I process the content I replace all HTML tags (including < and >) with some (hopefully) unique characters ($%&) followed by a number, and I save the HTML tag to array (the number is the index of the tag being replaced). Then after the “wbr” insertion I replace the unique characters with the tags I stored.
A quick demonstration on how to use the class (use freely, no guaranties):
$o = new WbrInserter (); echo $o->InsertHtmlWbr ( 'text with HTML tags' ); // use this method if you have HTML tags in your content echo $o->InsertPlainWbr ( 'text without HTML tags' ); // use this method if your content doesn’t include HTML tags
Comments
Comment from Крыс
Time May 26, 2009 at 11:07 pm
Наткнулся случайно на Ваш блог. Теперь стану постоянно просматривать. Надеюсь, не разочаруете и дальше
Pingback from Jan Hančič » Handling layout breaking text
Time January 31, 2009 at 6:15 pm
[...] tag in the middle of them. I’ll try to come up with a solution when I find some time. Read this post if you have HTML tags in your content and you wish to use this [...]