Using preg_match many time to check if strings are in text
I have a text from a text area, which contains 4 necessary strings. Before
I insert this text on the database I check for the presence of those
strings.
Is there a better and alternative way than do 4 preg_match operations,
maybe using preg_match_all?
If I'd like to replace those 4 strings with something else, where is the
difference between preg_replace and str_replace. Which should I use?
Here my code:
if(isset($_POST['text'])){
$text= $link->real_escape_string($_POST['text']);
$string = $text;
$pattern1 = '/LIMITE_TYPE/';
$pattern2 = '/LIMITE_SET/';
$pattern3 = '/TODAY_PRICE/';
$pattern4 = '/AUTO_SIGN/';
if(preg_match($pattern1, $string)
&& preg_match($pattern2, $string)
&& preg_match($pattern3, $string)
&& preg_match($pattern4, $string))
{
echo 'ok';
}else{
echo 'not found';
}
die();
}
No comments:
Post a Comment