Say, I had a page called www.mysite.com/download/page_is_good.html How would I go about making the <title> of the page like this <title>Page Is Good</title> from the URL? So it runs through the page link, and then makes the title whatever the page name is minus the _ and .html and capitilises the words? I seen it was done before, but can't find the thread I read a while back
Hi! Not sure what you are after. Something like this: <title><?php echo ucwords(str_replace('_', ' ', $_SERVER['PHP_SELF'])) ?></title> PHP: Or different? Regards - P
This works, however it echos /download.php instead of say "cool icon" from /cool_icon.html I think its because of .htacess. Anyway around this?
Hmm, thought that worked, but nope. What that new code did was just get rid of the / before download.php So now it echos download.php as the title instead of /download.php --- This is how the script works. I have in the base directory download.php then a directory called download/ download.php does all the work, however, in download directory is a .htaccess file that make things like this download.php?cat=2?id=3 look like /download/cool_graphic_3.html I need it to echo, "cool graphic 3" in the title if that were the case. Cheers penagate for the help, I really appreciate it and gave you some rep!
My mistake. Try: $f = ucwords(str_replace('_', ' ', basename($_SERVER['PHP_SELF']))); $f = substr($f, 0, strrpos($f, '.')); PHP: Regards - P
Put that snippet in a <?php ... ?> block somewhere at the top of your page before the HTML and then use this line: <title><?php echo $f ?></title> Code (markup):
Just FYI, you can also use an equivalent of echo for small outputs like this: <title><?=$f?></title> PHP:
Hmm, that just makes it say "download" now. Sorry, anything else! We're making progress though eliminating the ones that don't work! hehe Thanks again for the help!
You might be able to on your installation, but I strongly advise against it. Short tags are disabled by default in PHP 5, and also by many web hosts, as they conflict with XML processing instructions. Thus, you should never use them in a production situation, as they are not portable code. Also, I believe they will be removed in PHP 6. It says "Download" for me with a file "download.php". Put echo('Basename: ' . basename($_SERVER['PHP_SELF'])) before the $f lines and tell me what that outputs.
You are wrong. short_open_tag turned on by default in php 5 and all php > 4.0 (http://www.php.net/ini.core). This flag can be always changed with .htaccess or ini_set if it is disabled by hoster.