检查当前 url 的代码,检查它是否包含某个字符串

a code that checks the current url, checks if it contains a certain string

Php condition

谁能帮我写一个检查当前 url 的代码,检查它是否包含某个字符串。

例如:/myaccount/orders

和returns正确

使用javascript你可以尝试如下: window.location.pathname 将给主字符串添加 url

<script type="text/javascript">
    
if ((window.location.pathname ===  '/orders') {
      console.log("orders url");
 }

</script>

如果php你可以试试这个:


    $URL = $_SERVER['PHP_SELF']);
    if (str_contains($URL, 'orders')) {
        print_r("URL contains orders");
    }