Hello.
It is necessary to determine with $ _SERVER [REQUEST_URI] whether the url of the current page ends in .html
How to make a mask, please tell me?
Hello.
It is necessary to determine with $ _SERVER [REQUEST_URI] whether the url of the current page ends in .html
How to make a mask, please tell me?
At least three ways (not counting regulars) comparison with the desired value:
Take the last characters in a string equal to the length of the string being compared:
$search = 'html'; $str = '/www/htdocs/inc/lib.inc.php'; $lastChars = substr($str, -strlen($search)); if ($search != $lastChars) echo 'Это строка не оканчивается на html'; substr - returns a substring of the string string starting at the specified position and specified. If the starting position is negative, the returned substring starts at the end of the line.
Smash through explode smash the separator "point" and take the last element
$search = 'html'; $str = '/www/htdocs/inc/lib.inc.php'; $exploded = explode('.', $str); $lastChars = array_pop($exploded); if ($search != $lastChars) echo 'Это строка не оканчивается на html'; Take advantage of pathinfo - returns information about the path to the file
$str = '/www/htdocs/inc/lib.inc.php'; $path_parts = pathinfo($str); echo 'dirname: ' . $path_parts['dirname'], "<br/>"; echo 'basename: ' . $path_parts['basename'], "<br/>"; echo 'extension: ' . $path_parts['extension'], "<br/>"; echo 'filename: ' . $path_parts['filename'], "<br/>"; // начиная с PHP 5.2.0 if ($search != $path_parts['extension']) echo 'Это строка не оканчивается на html'; Regulars.
Source: https://ru.stackoverflow.com/questions/669543/
All Articles
.html....... or break through theexplodewith a dot separator and take the last element of the resulting array and compare withhtml- Alexey Shimansky