samedi 11 août 2018

strpos or preg_match when trying find a string with sequence of numbers at the end?

I'm trying to create an IF statement when there is a string within the current URL which is partly working but returning some unwanted results.

// set patterns active
if ( $option == 'pattern' ) {
$patternvalue = "pattern=" . $v['id'];
$optionset = strpos($_SERVER['REQUEST_URI'], $patternvalue);
if ($optionset !== false) {
echo ' class="active" ';
}
}

Using the above code if the pattern=16 then the code is echoing the class="active" for pattern=16 but also pattern=1... It seems to be matching only up to the first number.

I don't know if I should be using preg_match instead but am an complete novice and don't quite know how to get it working with all the back and forward slashes required.

A typical url ending may look like: /?action=search&pattern=23&fabric=13&type=2

Aucun commentaire:

Enregistrer un commentaire