A simple line of PHP corrupts WordPress

I am trying to implement this code into WordPress:

<?php
    $basename = substr(strtolower(basename($_SERVER['PHP_SELF'])),0,strlen(basename($_SERVER['PHP_SELF']))-4);
?>

No matter in which of the WordPress php files I put this in, it corrupts it. Saying that it cannot find the page. This is very bizarre. Do anyone know why it is behaving like this? Or any direct solutions to how I can add this code to WordPress?

Read More

Note that I am not experienced with PHP so any respond with detail would be appreciated.

Related posts

Leave a Reply

3 comments

  1. This is a parse error.

    You need a closing bracket at the end:

      $basename = substr(strtolower(basename($_SERVER['PHP_SELF'])),0,strlen(basename($_SERVER['PHP_SELF']))-4)
    

    It’s a good thing to use a text editor or IDE with syntax highlighting that can reveal such things, they are often difficult to see with the naked eye.

    That said, as @JMC Creative points out, this looks very kludgy, and there is bound to be a better way to achieve what you want. What is the goal of this?

  2. You’re over-complicating what you’re trying to do.

    $fileName = strtolower(basename(__FILE__, ".php"));

    You may want to use php_self instead of file, it depends on what you’re after.