简体   繁体   中英

how can i do first variable like second variable in php

my code is

<?php if($_SERVER['REQUEST_URI'] == "/scripts/script1.php")
    {
        echo 'yes';
    }
    else
    {
        echo 'no';
    }

some time my URL come like

www.example.com/scripts/script1.php?var1=value1&var2=value2

How can do that with PHP

URL like function....

Make use of strpos in PHP

  <?php 
       if(strpos($_SERVER['REQUEST_URI'],"/scripts/script1.php")!==false)
        {
            echo 'yes';
        }
        else
        {
            echo 'no';
        }

A slight variation on Shankar's answer

   $result = "no";
   if( strpos( $_SERVER[ "REQUEST_URI" ], "/scripts/script1.php" ) !== false ) {
        $result = "yes";
   }

By setting the default value for the variable, you can make your code more concise and improve readability.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM