gpt4 book ai didi

php: 如果当前 url 包含 "/demo"执行某些操作

转载 作者:行者123 更新时间:2023-12-02 21:35:35 24 4
gpt4 key购买 nike

我想检查我当前的 URL 末尾是否包含“/demo”,例如 mysite.com/test/somelink/demo 来执行某些操作。这是我的尝试:

$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'mysite.com/test/somelink/demo')
{
// Do something
}
else
{
// Do something
}

这似乎工作正常,但问题是 /somelink 需要动态。

关于如何执行此操作有什么建议吗?

谢谢!

编辑:

<?php
/* An abstract class for providing form types */
abstract class ECF_Field_Type {
private static $types = array();
protected $name;

/* Constructor */
public function __construct() {
self::register_type( $this->name, $this );
}

if(basename($_SERVER['REQUEST_URI']) == 'stats'){
echo "Hello World";
}

/* Display form field */

public abstract function form_field( $name, $field );

/* Display the field's content */
public function display_field( $id, $name, $value ) {
return "<span class='ecf-field ecf-field-$id'>"
. "<strong class='ecf-question'>$name:</strong>"
. " <span class='ecf-answer'>$value</span></span>\n";
}


/* Display field plain text suitable for email display */
public function display_plaintext_field( $name, $value ) {
return "$name: $value";
}

/* Get the description */
abstract public function get_description();
}
?>

最佳答案

只需使用,

if(basename($_SERVER['REQUEST_URI']) == 'demo'){
// Do something
}

关于php: 如果当前 url 包含 "/demo"执行某些操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21458195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com