SBoudrias
891 Posts htmlentities () returns ventilation the character string with special characters encods in ASCII code. This code is not properly spoken an encoding method of character, so there is no need to decode the output; it is read by the browser. That said! Attention pass your string in htmlentities () will not make scuritaire for your base gives, and the risks of XSS still Introduced. The best would be to go through a filter (Filter made a research or filter_var ()). For your problem with substring, if you pass in your string htmlentities () is all natural that substring behaves well. You did that spcifier a larger number ... or use regexp.
Posts 4671 There is no reason to use htmlentities if you are in UTF-8. You must use htmlspecialchars () that will convert ventilation some characters like <,>, "... ventilation In addition as you are in UTF-8 the result of substr will be wrong on a chain containing accents. You have . use the mbstring extension and its functions as mb_substr () http://www.php.net/manual/fr/book.mbstring.php tonymx15 a crit: SECOND ventilation Then my problem is that when I use substr () to dcouper a string ventilation that contains a character spciaux, if unfortunately the s'rrete dcoupe to Milleur a character spciaux so that if is transformed first, but HTML character is shot Dcoupe your chain to the nearest word rather. // charset configuration for mbstring mb_internal_encoding ('UTF-8'); ventilation function truncate_text ($ string, $ limit, $ break = '', $ pad = '') {// return with no change if string is go short than $ + $ pad length limit if (mb_strlen ($ string) <= $ limit + mb_strlen ($ pad)) return $ string $ string = mb_substr ($ string, 0, $ limit); if (! == false ($ breakpoint = mb_strrpos ($ string, $ break))) $ string = mb_substr ($ string , 0, $ breakpoint) return trim ($ string) $ pad.; } $ String = 'Voil truncate the text'; $ String = truncate_text ($ string, 10); Modified by jb_gfx (09 May 2011 - 11:27 p.m.)
Go Home gnrales Questions and Semantic Web beginners question and HTML, XHTML, HTML5 Mobile Web responsive web design and formatting CSS, CSS3, JavaScript, DOM and HTML5 API Web Accessibility Web Formats , encoding, internationalization, ventilation XML ct Web Development Server Reviews of your sites: Bar code and design forum
Alsacréations is a community dedicated to designing websites and web applications quality, thanks to the W3C standards, CSS stylesheets, HTML and JavaScript, and accessibility
No comments:
Post a Comment