note 53579 added to function.strstr

From: Date: Mon, 06 Jun 2005 16:13:53 +0000
Subject: note 53579 added to function.strstr
Groups: php.notes 
Request: Send a blank email to php-notes+get-90013@lists.php.net to get a copy of this message
suggestion for [leo dot nard at free dot fr]: to be able to cut the string without having the html entities being cut in half, use this instead: <?php $oldstr = "F&ouml;r att klippa av en str&auml;ng som inneh&aring;ller skandinaviska (eller Franska, f&ouml;r den delen) tecken, kan man g&ouml;ra s&aring;h&auml;r..."; $length = 50; # First, first we want to decode the entities (to get them as usual chars), then cut the string at for example 50 chars, and then encoding the result of that again. # Or, as I had it done, in one line: $newstr = htmlentities(substr(html_entity_decode($oldstr), 0, $length)); $newstr2 = substr($oldstr, 0, $length); # It's not quite as much code as the snippet you've coded to remove the half-portions... ;) # Hopefully somebody finds this useful! echo "Without the decode-encode snippet: $newstr2 With the decode-encode snippet: $newstr"; ?> The above outputs this: Without the decode-encode snippet: F&ouml;r att klippa av en str&auml;ng som inneh&ar With the decode-encode snippet: F&ouml;r att klippa av en str&auml;ng som inneh&aring;ller skandin First post in this db ;) Best regards, Mikael Rönn, FIN ---- Manual Page -- http://www.php.net/manual/en/function.strstr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53579 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53579&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53579&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53579&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53579&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53579&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53579&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90013) next »