paruby Posted August 10, 2010 Share Posted August 10, 2010 i have an admin page that lists all the rows from a table. One of the fields is generated using FCKEditor, so the field has HTML Code in it. I would like to only show the first 100 or so chars of the field, but if the 100 chars ends in the middle of HTML code, specifically in this case <a href>, it cuts off, and creates "havoc" in my page. Is there a way to avoid this by seeing that the 100 char is in the middle of an <a href> tag (or any tag for that matter? Here is what the generated html can look like :: <td class="tdresults">We are very excited to offer three great events at the <a href="http://www.mylongwebsite.c</td> <td class="tdresults">next field data</td> Thank you in advance. Pete Quote Link to comment https://forums.phpfreaks.com/topic/210285-embedded-code-cut-short-undesired-results/ Share on other sites More sharing options...
gizmola Posted August 10, 2010 Share Posted August 10, 2010 Regular expressions are very good for solving this type of problem. There's also htmlentities() which will turn the html into entities. If this is an admin system as you describe providing an informational display, htmlentities might be a great quick solution. Once you've run it on the original string, you can concat whereever you want and have no concerns about anything being broken. Quote Link to comment https://forums.phpfreaks.com/topic/210285-embedded-code-cut-short-undesired-results/#findComment-1097332 Share on other sites More sharing options...
abdfahim Posted August 10, 2010 Share Posted August 10, 2010 Use htmlspecialchars http://php.net/manual/en/function.htmlspecialchars.php Quote Link to comment https://forums.phpfreaks.com/topic/210285-embedded-code-cut-short-undesired-results/#findComment-1097333 Share on other sites More sharing options...
paruby Posted August 11, 2010 Author Share Posted August 11, 2010 Thank you both for the suggestions. I actually found "strip_tags()" while looking at the first 2 suggestions. I am using that, as it seems "cleaner"... If not for your suggestions, i may not have found it...! Pete Quote Link to comment https://forums.phpfreaks.com/topic/210285-embedded-code-cut-short-undesired-results/#findComment-1097910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.