View Full Version : <title></title> location
Hello,
1) Is it possible to move the <title></title> out side of the <head> </head>?
2) Is it possible to change your title on every page of your site with one file without changing it on every page?
Please and thank you!
Master_script_maker
01-02-2008, 09:14 PM
1. its possible, but it won't work and will probably end up in error.
2. yes, if you want i can try to make it.(are your files .php , or .htm and .html)
Hello,
1) No.
2) Yes, if you use a server side scripting system. Or if you just want this to be observable by the users(not the search engines) you can change the document.title property form JavaScript.
Thanks, can you try to make it please! Thank you!
Master_script_maker
01-03-2008, 01:03 AM
save it as rename.php, upload it to your server, and run it. It will go through all your folders.
Changed file_put_contents to fwrite for compatablity issuses
Must have 777 file permisions
<?php
function getdir($dir) {
$title="";//edit this to what you want the title to be
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file=='rename.php'||$file=='..'||$file=='.') {
} else {
if (strpos($file, '.html',1)||strpos($file, '.htm',1)) {
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
fwrite($dir.$file, $file_content);
}
if (is_dir($dir.$file)) {
$dirs[]=$file;
}
}
}
closedir($handle);
}
for($i=0;$i<count($dirs);$i=$i+1) {
getdir($dir.$dirs[$i].'/');
}
}
getdir('./');
?>
Thanks a lot. Can you briefly explain how it works please? Thank you!
codeexploiter
01-03-2008, 03:17 AM
I really wonder why you want to change the position of title tag?
Master_script_maker
01-03-2008, 09:03 PM
I really wonder why you want to change the position of title tag?
probably to be able to edit it with javascript.
Thanks a lot. Can you briefly explain how it works please? Thank you!
sure.
if ($handle = opendir($dir)) {
if the folder is openable and you can set it to a variable, set it to "$handle" and open it
while (false !== ($file = readdir($handle))) {
while there are files not read, set one of their names to a variable($file)
if ($file=='rename.php'||$file=='..'||$file=='.') {
} else {
if the file is this one, or a folder above this one do nothing, if it is not continue.
if (strpos($file, '.html',1)||strpos($file, '.htm',1)) {
if the filename contains '.html' or '.htm', continue
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
file_put_contents($dir.$file, $file_content);
replace '<title>somethiing</title>' with '<title>your title</title>' from the contents of the file(The '$dir' is the path). then it saves the file.
if (is_dir($dir.$file)) {
$dirs[]=$file;
}
if the 'file' is a folder add it to an array of folders.
closedir($handle);
close the opened folder
for($i=0;$i<count($dirs);$i=$i+1) {
getdir($dir.$dirs[$i].'/');
}
for each folder, run the function again with that one
getdir('./');
run the function in the current folder
Does it matter what my page extention is? Mine is .php
Master_script_maker
01-04-2008, 12:14 AM
if you want php change this:
if (strpos($file, '.html',1)||strpos($file, '.htm',1)) {
to this:
if (strpos($file, '.html',1)||strpos($file, '.htm',1)||strpos($file, '.php',1)) {
Err, I think I have misunderstood the second question. Never mind, Master_script_maker had done it well :)
Thanks! I get an error saying "Fatal error: Call to undefined function: file_put_contents() in /home/athletes/public_html/rename.php on line 10" when I run rename.php
thetestingsite
01-04-2008, 11:20 PM
Is your host running PHP5? If not, that would be the reason as file_put_contents was created in PHP5 and is non-existent in earlier versions.
Hope this helps.
As an alternative, you can use fwrite() (http://php.net/fwrite) in place of file_put_contents on the following line:
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
file_put_contents($dir.$file, $file_content);
tech_support
01-05-2008, 12:32 AM
probably to be able to edit it with javascript.
You can just edit it by using document.title='mynewtitlehere'...
<?php
function getdir($dir) {
$title="TITLE IS CHANGED";//edit this to what you want the title to be
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file=='rename.php'||$file=='..'||$file=='.') {
} else {
if (strpos($file, '.html',1)||strpos($file, '.htm',1)||strpos($file, '.php',1)) {
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
}
if (is_dir($dir.$file)) {
$dirs[]=$file;
}
}
}
closedir($handle);
}
for($i=0;$i<count($dirs);$i=$i+1) {
getdir($dir.$dirs[$i].'/');
}
}
getdir('./');
?>
That's my code so far and now when I run rename.php, nothing shows up.
Master_script_maker
01-06-2008, 06:38 PM
this:
<?php
function getdir($dir) {
$title="TITLE IS CHANGED";//edit this to what you want the title to be
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file=='rename.php'||$file=='..'||$file=='.') {
} else {
if (strpos($file, '.html',1)||strpos($file, '.htm',1)||strpos($file, '.php',1)) {
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
}
if (is_dir($dir.$file)) {
$dirs[]=$file;
}
}
}
closedir($handle);
}
for($i=0;$i<count($dirs);$i=$i+1) {
getdir($dir.$dirs[$i].'/');
}
}
getdir('./');
?>
is supposed to be this:
<?php
function getdir($dir) {
$title="";//edit this to what you want the title to be
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file=='rename.php'||$file=='..'||$file=='.') {
} else {
if (strpos($file, '.html',1)||strpos($file, '.htm',1)||strpos($file, '.php',1)) {
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
fwrite($dir.$file, $file_content);
}
if (is_dir($dir.$file)) {
$dirs[]=$file;
}
}
}
closedir($handle);
}
for($i=0;$i<count($dirs);$i=$i+1) {
getdir($dir.$dirs[$i].'/');
}
}
getdir('./');
?>
Ok, now I get
"Warning: fwrite(): supplied argument is not a valid stream resource in /home/athletes/public_html/rename.php on line 10" repeating about a 100 times on the page.
http://www.athletes4excellence.com/rename.php
Is it better to just use a php template than doing this?
Master_script_maker
01-06-2008, 06:50 PM
try replacing this:
fwrite($dir.$file, $file_content);
with this:
$totalfile=fopen($dir.$file, 'w');
fwrite($totalfile, $file_content);
fclose($totalfile);
I am now getting Warning: fwrite(): supplied argument is not a valid stream resource in /home/athletes/public_html/rename.php on line 11 repeated hundreds of times in the page.
Master_script_maker
01-06-2008, 07:02 PM
what does it say if you change/add this:
echo $totalfile;
echo fwrite($totalfile, $file_content);
It says this "Warning: fwrite(): supplied argument is not a valid stream resource in /home/athletes/public_html/rename.php on line 11"? I'm not sure what you mean by your last post.
Master_script_maker
01-06-2008, 07:11 PM
add
echo $totalfile;
and change
fwrite($totalfile, $file_contents);
with
echo fwrite($totalfile, $file_contents);
<?php
function getdir($dir) {
$title="FIELENAMEKREJRKE";//edit this to what you want the title to be
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file=='rename.php'||$file=='..'||$file=='.') {
} else {
if (strpos($file, '.html',1)||strpos($file, '.htm',1)) {
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
echo $totalfile;
echo fwrite($totalfile, $file_contents);
}
if (is_dir($dir.$file)) {
$dirs[]=$file;
}
}
}
closedir($handle);
}
for($i=0;$i<count($dirs);$i=$i+1) {
getdir($dir.$dirs[$i].'/');
}
}
getdir('./');
?>
Is that code right?
Master_script_maker
01-06-2008, 07:24 PM
no, try this:
<?php
function getdir($dir) {
$title="FIELENAMEKREJRKE";//edit this to what you want the title to be
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file=='rename.php'||$file=='..'||$file=='.') {
} else {
if (strpos($file, '.html',1)||strpos($file, '.htm',1)) {
$file_content = preg_replace('/<title>(.*?)<\/title>/', '<title>'.$title.'</title>', file_get_contents($dir.$file));
$totalfile=fopen($dir.$file, "w");
fwrite($totalfile, $file_contents);
fclose($totalfile);
}
if (is_dir($dir.$file)) {
$dirs[]=$file;
}
}
}
closedir($handle);
}
for($i=0;$i<count($dirs);$i=$i+1) {
getdir($dir.$dirs[$i].'/');
}
}
getdir('./');
?>
Now I get,
"Warning: fopen(./mattreedprofile.html.wpd) [function.fopen]: failed to open stream: Permission denied in /home/athletes/public_html/rename.php on line 10
Warning: fwrite(): supplied argument is not a valid stream resource in /home/athletes/public_html/rename.php on line 11
Warning: fclose(): supplied argument is not a valid stream resource in /home/athletes/public_html/rename.php on line 12"
repeating hundreds of times.
thetestingsite
01-06-2008, 11:03 PM
One thing that everyone is forgetting to mention is that you must have 777 permissions on the files that you want to rename.
Hope this helps.
Master_script_maker
01-06-2008, 11:05 PM
thanks, forgot to mention that, that should solve the problem
Still get the errors, http://www.athletes4excellence.com/rename.php
thetestingsite
01-07-2008, 12:17 AM
I have a question. Are you really wanting to rename the title of every page to the same thing? If so, the code should work; if not, you may want to look into making a template and then using variables to make the title change. I recommend you use Smarty Templates (http://smarty.php.net/). Other than that, check to make sure that the files do in fact have 777 permissions.
Hope this helps.
Yes, I do not want to rename all my pages to that page. Thanks for reminding me and thanks for that link! Also, can you briefly explain how templates work please?
Master_script_maker
01-08-2008, 12:22 AM
Still get the errors, http://www.athletes4excellence.com/rename.php
are you sure they're chmod 777, it looks like their not
Master_script_maker
01-08-2008, 12:26 AM
...can you briefly explain how templates work please?
it looks like you will still have to edit all of the files
Well, I noticed that, all my titles will be the same... and that's not what I want.
tech_support
01-08-2008, 03:42 AM
What do you want then? If you want to make each page title separate, then all you have to do is change them manually.
Is there a benefit of using templates?
BLiZZaRD
01-09-2008, 01:31 AM
To change the title of every page? No.
If you have "categories" though. Then maybe. Say you have 3 main "sections" of your site, and after a while you want to include a new category into the 2nd one, instead of adding new titles to the pages already in section 2, you could use the template to make the change for you.
A basic rule of thumb for page/web design is if you do it once, just do it. If you repeat the same thing more than twice, find an easier way.
In this case, if you are just changing a title to one page, do it manually. If you are changing the title of 12 pages to the same title, use a template.
tech_support
01-09-2008, 01:32 AM
Try this tutorial (http://www.dynamicdrive.com/forums/showthread.php?p=125609) on templates. Wrote it just now. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.