Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard in an if statement

Tags:

php

is it possible to use wildcard in an if statement? My code:

*=wildcard
if ($order_info=='Quatro*') {

}

$order_info will be "Quatro - na splátky", or "Quatro - čťžýáí"

like image 364
Adrian Avatar asked Oct 20 '25 04:10

Adrian


2 Answers

Use regex:

if (preg_match('/^Quatro/', $order_info)) {

}

or strpos:

if (strpos($order_info, 'Quatro') === 0) {

}

Edit: Avoiding regex engine invocation for simple string matches like this is usually preferred. strpos will do the same job less expensively.

like image 92
webbiedave Avatar answered Oct 21 '25 19:10

webbiedave


Sure, use a regex:

if( preg_match( '/^Quatro.*/', $order_info))
{
}
like image 35
nickb Avatar answered Oct 21 '25 18:10

nickb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!