0

Hello I tried to configured my Title on my website. My idea is, any page needs to read the command "include header.php" and automatically update the website title. I found that script but I can't hide .php extension.

Any ideia?

<title>
<?php

$current_file_name = basename($PHP_SELF);
echo $current_file_name."\n"


?> | Site Name</title>
FirstOne
  • 6,033
  • 7
  • 26
  • 45

3 Answers3

1

This will give you an array of all the goodies you need. In this case, you're looking for the 'filename'.

<?php
$parts = pathinfo(__FILE__);
print_r($parts);

You can use this as so:

<?php
$parts = pathinfo(__FILE__);
echo "<title>{$parts['filename']}</title>";
waterloomatt
  • 3,662
  • 1
  • 19
  • 25
0

I'm not sure this is what you want but if you want to remove the string .php in your string $current_file_name, you can replace it with "" with str_replace :

<title>
<?php

$current_file_name = basename($PHP_SELF); // = "header.php"
$current_file_name = str_replace(".php", "", $current_file_name); // = "header"
echo $current_file_name."\n";


?> | Site Name</title>
Flo
  • 356
  • 1
  • 11
0

you can hide .php extension using .htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
Vijay Arun
  • 414
  • 8
  • 15