stevesimo Posted December 13, 2007 Share Posted December 13, 2007 Hi, I am trying to use SUBSTR to simply output the first 50 letters of a string. Here is my code $showinfo = $show['showinfo']; $info = substr($showinfo, 0, 50); echo $info; [code] The problem is that my output is only 30 chars (see below for example output) An exhibition of the best loca One of the largest regional we Can anyone see what I am doing wrong? Thanks, Steve [/code] Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 are you sure that showinfo in your database has more that 30 character check the field size. your substr syntax is correct. Quote Link to comment Share on other sites More sharing options...
stevesimo Posted December 13, 2007 Author Share Posted December 13, 2007 Yes, if I dont use substr and simply output the value there is always more than say 100 chars. I have set the database field type as text although I havent specified any other parameters. When I check the database using PhpMyAdmin the values are all stored. HTML is also stored within some of the tags. Could this be causing the problem? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 13, 2007 Share Posted December 13, 2007 If there are HTML tags in the string, you should use the htmlentities() function when you echo the value to ensure that the tags are not interpreted. <?php echo htmlentities(substr($show['showinfo'],0,50),ENT_QUOTES); ?> Ken Quote Link to comment 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.