jeudi 29 juin 2017

Search for Specific Text with Special Characters in a String in PHP

I am using a script to check if a string $status contains the following text or not -

SC-102 || EOD-103 || EOD-31 || DLYDC-104 || EOD-72 || ST-108 || SC-104 || X-SC || EOD-114 || DLYMR-118 || EOD-76 || EOD-6 || EOD-95 || EOD-69 || EOD-16 || EOD-2 || EOD-97 || EOD-110 || EOD-15 || EOD-32 || EOD-107 || EOD-106 || EOD-46 || EOD-104 || EOD-42 || EOD-7 || EOD-111 || EOD-43

|| is used to represent OR

The Letters, Special Characters & Numbers are one single piece of TEXT. For. Example - ST-102 is an exact text to be search from $status

My present code looks like the following -

$codes = array("SC-102","EOD-103","EOD-31","DLYDC-104","EOD-72","ST-108","SC-104","X-SC","EOD-114","DLYMR-118","EOD-76","EOD-6","EOD-95","EOD-69","EOD-16","EOD-2","EOD-97","EOD-110","EOD-15","EOD-32","EOD-107","EOD-106","EOD-46","EOD-104","EOD-42","EOD-7","EOD-111","EOD-43");

if($status_code==$codes)
{
//My Script , if condition is true!
}

Aucun commentaire:

Enregistrer un commentaire