danielstjules / Stringy

A PHP string manipulation library with multibyte support
MIT License
2.46k stars 216 forks source link

New feature, highlight text suport utf8 #128

Closed webmailcontatos closed 8 years ago

webmailcontatos commented 8 years ago

Hi, this new feature allows involve part of the string in an html tag. Congratulations tool

danielstjules commented 8 years ago

Thanks for the PR! Looks interesting, but seems a little too specific for this library.

Your function and example:

(string) S::create('Ácido Lático')->highlight('á');
<span class="highlight">Á</span>cido L<span class="highlight">á</span>tico

Can be replicated using regexReplace:

(string) s('Ácido Lático')->regexReplace('(á)', '<span class="highlight">\\1</span>', 'msri')
webmailcontatos commented 8 years ago

Hi,

$result = (string) s('Ácido Lático')->regexReplace('(aci)', '<span class="highlight">\1', 'msri');

$expected = 'Ácido Úrico';

Não funcionou, voĉe pode me ajudar?

Thanks

2016-03-19 21:48 GMT-03:00 Daniel St. Jules notifications@github.com:

Thanks for the PR! Looks interesting, but seems a little too specific for this library.

Your function and example:

(string) S::create('Ácido Lático')->highlight('á');Ácido Lático

Can be replicated using regexReplace:

(string) s('Ácido Lático')->regexReplace('(á)', '\1', 'msri')

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/danielstjules/Stringy/pull/128#issuecomment-198816388

webmailcontatos commented 8 years ago

It does not work, you can help me?

2016-03-21 12:58 GMT-03:00 Thiago Guimarães webmailcontatos@gmail.com:

Hi,

$result = (string) s('Ácido Lático')->regexReplace('(aci)', '\1', 'msri');

$expected = 'Ácido Úrico';

Não funcionou, voĉe pode me ajudar?

Thanks

2016-03-19 21:48 GMT-03:00 Daniel St. Jules notifications@github.com:

Thanks for the PR! Looks interesting, but seems a little too specific for this library.

Your function and example:

(string) S::create('Ácido Lático')->highlight('á');Ácido Lático

Can be replicated using regexReplace:

(string) s('Ácido Lático')->regexReplace('(á)', '\1', 'msri')

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/danielstjules/Stringy/pull/128#issuecomment-198816388

danielstjules commented 8 years ago

Oops, the i flag for case insensitive matches only works in PHP > 5.6 and newer version of HHVM https://github.com/danielstjules/Stringy#regexreplacestring-pattern-string-replacement--string-options--msr

If you're unable to upgrade to PHP 5.6, I'd recommend maintaining a simple wrapper/child class extending Stringy with your highlight function. :)

webmailcontatos commented 8 years ago

Hi, This test run in php :

PHP 5.6.11-1+deb.sury.org~utopic+1 (cli) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans I wonder what could have happened then?

2016-03-21 13:08 GMT-03:00 Daniel St. Jules notifications@github.com:

The i flag for case insensitive matches only works in PHP > 5.6 and newer version of HHVM

https://github.com/danielstjules/Stringy#regexreplacestring-pattern-string-replacement--string-options--msr

If you're unable to upgrade to PHP 5.6, I'd recommend maintaining a simple wrapper/child class extending Stringy with your highlight function. :)

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/danielstjules/Stringy/pull/128#issuecomment-199359373

danielstjules commented 8 years ago

Are you sure you didn't just forget the accent in your previous example? E.g. (aci) => (áci)

I just tested locally:

(string) s('Ácido Lático')->regexReplace('(áci)', '<span class="highlight">\\1</span>', 'msri')
// =>
<span class="highlight">Áci</span>do Lático