PHP code example of menthol / sql-like-to-regex
1. Go to this page and download the library: Download menthol/sql-like-to-regex library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
menthol / sql-like-to-regex example snippets
use Menthol\SqlLikeToRegex\SqlLikeToRegex;
print (new SqlLikeToRegex)
->setPattern('foo%')
->toRegex();
// => /^foo.*$/i
var_dump((new SqlLikeToRegex)
->setPattern('foo%')
->test('FooBar')
);
// => bool(true)
var_dump((new SqlLikeToRegex)
->setPattern('foo%')
->test('Baz')
);
// => bool(false)
print (new SqlLikeToRegex)
->setPattern('B_o#(F%o##Moo#%')
->setEscape('#')
->setCaseSensitive()
->toRegex();
// => /^B.o\(F.*o#Moo%$/
print (new SqlLikeToRegex)
->setPattern('_b_a_r_')
->setDelimiter('#')
->toRegex();
// => #^.b.a.r.$#i
print (new SqlLikeToRegex)
->setPattern('/.*[baz]{5}^/')
->setDelimiter('<')
->toRegex();
// => <^/\.\*\[baz\]\{5\}\^/$>i