note 53579 added to function.strstr
| From: | php-general at lists dot php dot net | 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ör att klippa av en sträng som innehåller skandinaviska
(eller Franska, för den delen) tecken, kan man göra
såhä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ör att klippa av en sträng som inneh&ar
With the decode-encode snippet:
För att klippa av en sträng som innehå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