Skip to content

Instantly share code, notes, and snippets.

View iazaran's full-sized avatar
🦉
Night Owl

Ismael Azaran iazaran

🦉
Night Owl
View GitHub Profile
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use SmartCache\Facades\SmartCache;
// Sample of response
/*
{
@iazaran
iazaran / preg_2_chars.php
Created January 11, 2022 07:56
Extract string between 2 chars
$input = "Lorem ipsum [dolor] sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore [et dolore magna aliqua.] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur [sint occaecat] cupidatat non proident, sunt in [culpa qui] officia deserunt mollit anim id est laborum.";
preg_match_all('/\[(.*?)\]/', $input, $extracted);
$extractArray = $extracted[1];
foreach($extractArray as $found) {
echo $found . "\n";
}