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

[10.x] Add replaceMatches to Str class #48727

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

hosmelq
Copy link
Contributor

@hosmelq hosmelq commented Oct 14, 2023

This pull request adds the replaceMatches method to the Str class, which is already used in the Stringable class.

I don't think using the Stringable class to call this method is necessary.

This is my use case.

$result = (string) Str::of(file_get_contents($file))->replaceMatches(
    '/^(.*data-public-url=")([^"]*)(".*)$/m',
    '$1<?= e(Storage::disk(\'s3\')->temporaryUrl(\$item->path, now()->addHours(2))) ?>$3'
);

That could be.

$result = Str::replaceMatches(
    '/^(.*data-public-url=")([^"]*)(".*)$/m',
    '$1<?= e(Storage::disk(\'s3\')->temporaryUrl(\$item->path, now()->addHours(2))) ?>$3',
    file_get_contents($file)
);

Thank You!

@GrahamCampbell GrahamCampbell changed the title Add replaceMatches to Str class [10.x] Add replaceMatches to Str class Oct 14, 2023
@taylorotwell taylorotwell merged commit 1bae4cd into laravel:10.x Oct 16, 2023
20 checks passed
@hosmelq hosmelq deleted the add-replace-matches-to-str-class branch October 16, 2023 20:32
* @param int $limit
* @return string|string[]|null
*/
public function replaceMatches($pattern, $replace, $subject, $limit = -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static function replaceMatches() ??

timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 24, 2023
* add replaceMatches to Str class

* Update Str.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants