Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement StringHelper::findBetween Method #20034

Merged

Conversation

salehhashemi1992
Copy link
Contributor

@salehhashemi1992 salehhashemi1992 commented Oct 23, 2023

Implement the findBetween method in the StringHelper class.

This method retrieves a substring that lies between the first occurrence of a specified start string and the last occurrence of a specified end string in the input string.

Tests are included.

Usage

$htmlContent = "<div class='content'>Hello World</div>";
$content = StringHelper::findBetween($htmlContent, "<div class='content'>", "</div>");
$logData = "INFO: Start --- debug data --- End";
$debugData = StringHelper::findBetween($logData, "Start ---", "--- End");
$htmlData = "<html><body><a href="https://example.com">Link</a></body></html>";
$link= StringHelper::findBetween($htmlData, '<a href="', '">');

@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fcd9e0a) 48.00% compared to head (3d4e108) 48.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20034      +/-   ##
==========================================
+ Coverage   48.00%   48.01%   +0.01%     
==========================================
  Files         445      445              
  Lines       43887    43896       +9     
==========================================
+ Hits        21069    21078       +9     
  Misses      22818    22818              
Files Coverage Δ
framework/helpers/BaseStringHelper.php 99.44% <100.00%> (+0.02%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@salehhashemi1992 salehhashemi1992 marked this pull request as ready for review October 23, 2023 20:25
@salehhashemi1992 salehhashemi1992 changed the title Implement findBetween Method in StringHelper Implement StringHelper::findBetween Method Oct 23, 2023
@samdark samdark requested review from a team October 24, 2023 11:35
@bizley
Copy link
Member

bizley commented Oct 24, 2023

Do we need it? I don't have a strong opinion here.

@mtangoo
Copy link
Contributor

mtangoo commented Oct 24, 2023

@bizley I don't think it is necessary but since it is addition in the helper, I do not see any issue at all!

@salehhashemi1992 salehhashemi1992 force-pushed the feature/string-helper-get-between- branch from ebf9e1a to 5fe844c Compare October 25, 2023 20:41
@rhertogh
Copy link
Contributor

Is there an advantage of this function over a regular expression?

@salehhashemi1992
Copy link
Contributor Author

salehhashemi1992 commented Oct 27, 2023

Is there an advantage of this function over a regular expression?
@rhertogh

Isn't it much simpler to use?
Why do we define lots of validation helpers implemented by regular expressions?

@rob006
Copy link
Contributor

rob006 commented Oct 27, 2023

Is there an advantage of this function over a regular expression?

Not using regular expression is already an advantage. :D

BTW: I often implement similar helper, so IMO it is definitely useful.

@xepozz
Copy link
Member

xepozz commented Oct 30, 2023

Could you also port it to https://github.com/yiisoft/strings/blob/master/src/StringHelper.php?

@bizley
Copy link
Member

bizley commented Oct 30, 2023

Please add a changelog line, thanks.

@bizley bizley added this to the 2.0.50 milestone Oct 30, 2023
@salehhashemi1992 salehhashemi1992 force-pushed the feature/string-helper-get-between- branch from 5e8321e to 26032ad Compare October 30, 2023 10:20
@salehhashemi1992
Copy link
Contributor Author

Please add a changelog line, thanks.

Done

@bizley bizley merged commit 6804fbe into yiisoft:master Oct 30, 2023
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants