I'm trying to echo something if a regex is matched in a string in PHP.
When I do if(true){//...}
the suite executes, but when I do if(regex){//..}
it is not working.
By which I mean, the echo that is inside the suite is not executing.
What am I doing wrong?
Basically what I trying to do is echo something if $query looks like 2+2, 3* 5, or 4.0 / 1.2
Here is what is working:
<?php
if(true){
echo "<div class=\"calc\">Mathematical Operation</div>";
}
?>
And here is what is not working even though it should match $query, which is 2+ 2:
<?php
if(preg_match('/(\d+)(\s)*([+/*-])(\s)*(\d+)/', $query)){
echo "<div class=\"calc\">Mathematical Operation</div>";
}
?>