Skip to content

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

Merged
taylorotwell merged 2 commits into
laravel:10.xfrom
hosmelq:add-replace-matches-to-str-class
Oct 16, 2023
Merged

taylorotwell merged 2 commits into
laravel:10.xfrom
hosmelq:add-replace-matches-to-str-class

Conversation

@hosmelq

@hosmelq hosmelq commented Oct 14, 2023

Copy link
Copy Markdown
Contributor

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
@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
Copy Markdown
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