If you’re struggeling with regular Expressions I have a great tip for you. Just go to the website RegExr: Online Regular Expression Testing and put your regular expression together!

screenshot138

Besides the long if/else notation, the one that you’ll use in most cases, there is also an shorten notation. In this case the ‘ternary operator’ (?) is used.

$var = [condition] ? [true] : [false];
  • [condition] -> The condition that has to be true.
  • [true] -> The result if the condition is true.
  • [false] -> The result if the condition is not true.

The above is thus another way of scripting for:

if([condition]) { $var = [true]; } else { $var = [false]; }

Continue Reading »

Top of Page