if variable matches to a variable with multiple values

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
hermhart
Posts: 211
Joined: 13 Jan 2015 18:41

if variable matches to a variable with multiple values

Post by hermhart »

Is there a way, that if I get a list of values like so:

Code: Select all

 $overwrite = get("selecteditemsnames", "<crlf>");
And it returns the values for $overwrite as:
1.txt
2.txt
3.txt

That I can compare a variable with a single value to the list of values in $overwrite, and if it matches any of the values in $overwrite, than it performs the action, perhaps like so (though I cannot get it to work)?

Code: Select all

 $file = 2.txt;
 if (regexmatches($file, $overwrite, <crlf>)) {
    $contents = Action: OVERWRITE;
 }

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: if variable matches to a variable with multiple values

Post by highend »

Sure

but

1. Trying to match a list with a single item is wrong, it's the other way round
2. Your regexmatches() would not work anyway because the single item needs to be escaped before

Code: Select all

function IsIn($listOfVariables, $variable) {
    $esc = regexreplace($variable, "([\\.+(){\[^$])", "\$1" . "$");
    if (regexmatches($listOfVariables, $esc)) { return true; }
    return false;
}
or using gettokenindex() could be used for this (but only for full matches^^) as well...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

hermhart
Posts: 211
Joined: 13 Jan 2015 18:41

Re: if variable matches to a variable with multiple values

Post by hermhart »

Thanks!

Post Reply