Skip to content

Commit

Permalink
Merge pull request #19 from chriskonnertz/mb_substr
Browse files Browse the repository at this point in the history
Multibyte Support (Description)
  • Loading branch information
chriskonnertz committed Mar 29, 2016
2 parents 98d240c + bf2e8c4 commit 577875d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/ChrisKonnertz/OpenGraph/OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OpenGraph {
/**
* The version number
*/
const VERSION = '1.0.0';
const VERSION = '1.0.2';

/**
* The name prefix
Expand Down Expand Up @@ -301,11 +301,11 @@ public function description($description, $maxLength = 250)
$description = trim(strip_tags($description));
$description = preg_replace("/\r|\n/", '', $description);

$length = strlen($description);
$length = mb_strlen($description);

$description = substr($description, 0, $maxLength);
$description = mb_substr($description, 0, $maxLength);

if (strlen($description) < $length) {
if (mb_strlen($description) < $length) {
$description .= '...';
}

Expand Down
16 changes: 15 additions & 1 deletion tests/OpenGraphTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@ public function testRenderTags()
$hmtl = 'HTML: '.$og;
}

}
public function testMbDescription()
{
$og = $this->getDummy();

mb_internal_encoding('UTF-8');

$char = ''; // Unicode char U+263A (white smiley)

$og->description($char, 1);
$tag = $og->lastTag('description');

$this->assertEquals($tag->value, $char);
}

}

0 comments on commit 577875d

Please sign in to comment.