Giter VIP home page Giter VIP logo

php-htmltruncator's People

Contributors

judev avatar patkruk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-htmltruncator's Issues

Problem with Unicode characters

When I run unicode characters through truncate it doesn't come through correctly

Expected:

This is the greek letter beta: β

Actual:

This is the greek letter beta: β

Problem with adjacent HTML tags

Hey,

There seems to be a problem with adjacent HTML tags.

For example, try to truncate this to 25 characters:

<p>Lorem Ipsum</p><p>Lorem <div>Lorem Ipsum</div> Ipsum</p>

and check the output. You should notice an issue with the markdown.

If I change the second paragraph to h1, everything seems to be fine.

Fatal error when deprecated iconv extension is no longer available

Usages of HtmlTruncator, which is apparently no longer maintained, result in a fatal PHP error when the deprecated PHP extension iconv is no longer available. This is because the HTML5Lib sub-dependency, which is also not maintained, relies on iconv.

Fatal error: Uncaught Error: Class 'HTML5Lib\Exception' not found in /.../vendor/electrolinux/php-html5lib/src/HTML5Lib/InputStream.php:81

Require only stable versions

Using version ^1.0 for judev/php-htmltruncator
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- judev/php-htmltruncator 1.0.6 requires electrolinux/php-html5lib dev-master -> no matching package found.
- judev/php-htmltruncator 1.0.5 requires electrolinux/php-html5lib dev-master -> no matching package found.
- judev/php-htmltruncator 1.0.4 requires electrolinux/php-html5lib dev-master -> no matching package found.
- judev/php-htmltruncator 1.0.3 requires electrolinux/php-html5lib dev-master -> no matching package found.
- judev/php-htmltruncator 1.0.2 requires electrolinux/php-html5lib dev-master -> no matching package found.
- judev/php-htmltruncator 1.0.1 requires electrolinux/php-html5lib dev-master -> no matching package found.
- judev/php-htmltruncator 1.0.0 requires electrolinux/php-html5lib dev-master -> no matching package found.
- Installation request for judev/php-htmltruncator ^1.0 -> satisfiable by judev/php-htmltruncator[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6].

Non-self-closing tags without text get removed

The library removes non-self-closing tags without text, such as an iframe.

For example:

* string: <div class="media-pull-center media-width-full"><div class="embed-responsive embed-responsive-16by9"><iframe src="https://link.brightcove.com/services/player/" frameborder="0" allowfullscreen></iframe></div><div class="content-item__credit pull-right">Credit</div><div class="content-item__caption clearfix">Caption</div></div>
* length: 500
* result: <div class="media-pull-center media-width-full"><div class="content-item__credit pull-right">Credit</div><div class="content-item__caption clearfix">Caption</div></div>
* desired result: <div class="media-pull-center media-width-full"><div class="embed-responsive embed-responsive-16by9"><iframe src="https://link.brightcove.com/services/player/" frameborder="0" allowfullscreen></iframe></div><div class="content-item__credit pull-right">Credit</div><div class="content-item__caption clearfix">Caption</div></div>

Returning nothing (just "...") on certain input strings, but only at certain truncation lengths

I've got some autogenerated text in my database generated by https://github.com/fzaninotto/Faker

Some of the strings it generated seem to break php-htmltruncator. I noticed that these strings contain a bit of stuff like "* * * * * * * * * * *", so I'm wondering if this could be related to the cause.

Here's some code to demonstrate this...

$originalStrings[] = '* * * Gryphon. \'Then, you know,\' Alice gently remarked; \'they\'d  have been was not much like keeping so close to her, still it was growing, and very soon finished it off. * * * * * * * * * * * * * * * * * * * * * * * * * * * CHAPTER II. The Pool of Tears \'Curiouser and curiouser!\' cried Alice in a ring, and begged the Mouse was speaking, and this was the same thing, you know.\' \'And what are YOUR shoes done with?\' said the King, \'and don\'t look at the other side. The further off from England the nearer is to France-- Then turn not pale, beloved snail, but come and join the dance. Will you, won\'t you, will you, won\'t you, will you join the dance? Will you, won\'t you, will you join the dance. Will you, won\'t you, will you, won\'t you, will you, won\'t you join the dance. Would not, could not, would not, could not, would not, could not, would not give all else for two reasons. First, because I\'m on the same side of WHAT?\' thought Alice; \'I might as well as if she did not like to go down the little door into that lovely garden. First, however, she went round the court with a little now and then, if I might venture to ask any more questions about it, you may stand down,\' continued the Hatter, who turned pale and fidgeted. \'Give your evidence,\' the King put on one knee..';
$originalStrings[] = 'Gryphon. \'Then, you know,\' Alice gently remarked; \'they\'d have been was not much like keeping so close to her, still it was growing, and very soon finished it off. * * * * * * * * * * * * * * * * * * * * * * * * * * * CHAPTER II. The Pool of Tears \'Curiouser and curiouser!\' cried Alice in a ring, and begged the Mouse was speaking, and this was the same thing, you know.\' \'And what are YOUR shoes done with?\' said the King, \'and don\'t look at the other side. The further off from England the nearer is to France-- Then turn not pale, beloved snail, but come and join the dance. Will you, won\'t you, will you, won\'t you, will you join the dance? Will you, won\'t you, will you join the dance. Will you, won\'t you, will you, won\'t you, will you, won\'t you join the dance. Would not, could not, would not, could not, would not, could not, would not give all else for two reasons. First, because I\'m on the same side of WHAT?\' thought Alice; \'I might as well as if she did not like to go down the little door into that lovely garden. First, however, she went round the court with a little now and then, if I might venture to ask any more questions about it, you may stand down,\' continued the Hatter, who turned pale and fidgeted. \'Give your evidence,\' the King put on one knee..';
$originalStrings[] = 'Mock Turtle replied in a moment: she looked up, and there was no \'One, two, three, and away,\' but they were mine before. If I or she should meet the real Mary Ann, and be turned out of the lefthand bit. * * * * * * * * * * * * * * * * * * * * * CHAPTER II. The Pool of Tears \'Curiouser and curiouser!\' cried Alice again, for really I\'m quite tired of sitting by her sister sat still just as she ran..';
$originalStrings[] = 'White Rabbit read:-- \'They told me he was in such a thing before, but she got up, and there they are!\' said the Gryphon. \'I\'ve forgotten the words.\' So they went on just as if he were trying which word sounded best. Some of the lefthand bit. * * * * * * * * * * * * * * * * * \'Come, my head\'s free at last!\' said Alice a good character, But said I could shut up like telescopes: this time she heard was a real nose; also its eyes were getting so far off). \'Oh, my poor little feet, I wonder who will put on one of the soldiers did. After these came the guests, mostly Kings and Queens,.';

foreach($originalStrings as $originalString)
{
    echo "Original: " . $originalString;
    echo "<br>Original length: " . strlen($originalString);
    echo "<br>Truncated: ";
    $truncated = \HtmlTruncator\Truncator::truncate($originalString, 80/*, ['length_in_chars'=>true]*/);
    echo $truncated;
    echo "<br>Truncated length: " . strlen($truncated);
    echo '<hr>';
}

The above code outputs:

Original: * * * Gryphon. 'Then, you know,' Alice gently remarked; 'they'd have been was not much like keeping so close to her, still it was growing, and very soon finished it off. * * * * * * * * * * * * * * * * * * * * * * * * * * * CHAPTER II. The Pool of Tears 'Curiouser and curiouser!' cried Alice in a ring, and begged the Mouse was speaking, and this was the same thing, you know.' 'And what are YOUR shoes done with?' said the King, 'and don't look at the other side. The further off from England the nearer is to France-- Then turn not pale, beloved snail, but come and join the dance. Will you, won't you, will you, won't you, will you join the dance? Will you, won't you, will you join the dance. Will you, won't you, will you, won't you, will you, won't you join the dance. Would not, could not, would not, could not, would not, could not, would not give all else for two reasons. First, because I'm on the same side of WHAT?' thought Alice; 'I might as well as if she did not like to go down the little door into that lovely garden. First, however, she went round the court with a little now and then, if I might venture to ask any more questions about it, you may stand down,' continued the Hatter, who turned pale and fidgeted. 'Give your evidence,' the King put on one knee..
Original length: 1282
Truncated: …
Truncated length: 3
-
Original: Gryphon. 'Then, you know,' Alice gently remarked; 'they'd have been was not much like keeping so close to her, still it was growing, and very soon finished it off. * * * * * * * * * * * * * * * * * * * * * * * * * * * CHAPTER II. The Pool of Tears 'Curiouser and curiouser!' cried Alice in a ring, and begged the Mouse was speaking, and this was the same thing, you know.' 'And what are YOUR shoes done with?' said the King, 'and don't look at the other side. The further off from England the nearer is to France-- Then turn not pale, beloved snail, but come and join the dance. Will you, won't you, will you, won't you, will you join the dance? Will you, won't you, will you join the dance. Will you, won't you, will you, won't you, will you, won't you join the dance. Would not, could not, would not, could not, would not, could not, would not give all else for two reasons. First, because I'm on the same side of WHAT?' thought Alice; 'I might as well as if she did not like to go down the little door into that lovely garden. First, however, she went round the court with a little now and then, if I might venture to ask any more questions about it, you may stand down,' continued the Hatter, who turned pale and fidgeted. 'Give your evidence,' the King put on one knee..
Original length: 1275
Truncated: …
Truncated length: 3
-
Original: Mock Turtle replied in a moment: she looked up, and there was no 'One, two, three, and away,' but they were mine before. If I or she should meet the real Mary Ann, and be turned out of the lefthand bit. * * * * * * * * * * * * * * * * * * * * * CHAPTER II. The Pool of Tears 'Curiouser and curiouser!' cried Alice again, for really I'm quite tired of sitting by her sister sat still just as she ran..
Original length: 400
Truncated: …
Truncated length: 3
-
Original: White Rabbit read:-- 'They told me he was in such a thing before, but she got up, and there they are!' said the Gryphon. 'I've forgotten the words.' So they went on just as if he were trying which word sounded best. Some of the lefthand bit. * * * * * * * * * * * * * * * * * 'Come, my head's free at last!' said Alice a good character, But said I could shut up like telescopes: this time she heard was a real nose; also its eyes were getting so far off). 'Oh, my poor little feet, I wonder who will put on one of the soldiers did. After these came the guests, mostly Kings and Queens,.
Original length: 586
Truncated: …
Truncated length: 3

Changing the $length argument seems to affect it too. Try 10 words or 300 words and it works. But at 80 like above it breaks.

When length_in_chars is enabled...

  • 320 characters $length breaks all four examples
  • 100 characters $length works for all
  • 400 characters $length works with the third example, and breaks the rest.

Strange encoding issue

Hi, Firstly congratulations on the project. Its simply awesome!
However, I'm getting a strange a really strange issue and I ran out of options.
Default charset in php.ini is set to UTF-8, same symfony setting.
When I get the data from db all is fine, but after running this trough htmltruncator the encoding is wrong and I'm getting weird characters.
image

any idea what may cause this ? Please help

Unable to update to current version 1.2.2 via Composer.

Composer error:

 Your requirements could not be resolved to an installable set of packages.     Problem 1   - The requested package judev/php-htmltruncator 1.2.* exists as judev/php-htmltruncator[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.1.0, dev-master] but these are rejected by your constraint.

The Packagist website still shows 1.1.0 as well.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.