switch (substr($data,0,1)){
case '@': //if $data begins with @
mysqli_query($con,"SELECT * FROM table WHERE data LIKE '%$data%'");
break;
case '#': //if $data begins with #
mysqli_query($con,"SELECT * FROM table WHERE data LIKE '%$data%'");
break;
default: //neither of above
echo "your query doesn't begin with @ or #";
}
Edit for comment below :
You are looking for preg_match_all()
here is an example for what you want to do :
This will create 2 arrays
($hashes
, and $arobases
) containing the strings you want.
preg_match_all("(#[^\s]+)", "hello : #hash1 #hash2 @at1 @at2", $hashes);
preg_match_all("(@[^\s]+)", "hello : #hash1 #hash2 @at1 @at2", $arobases);
var_dump($hashes[0]);
echo "<br/><hr/>";
var_dump($arobases[0]);