Forum Moderators: coopster
so this is my problem :
I have file called config.php :
<?php
$site_url="http://mysite.com/folder-name/";
$tag_by_default="keyword";
$site_title="keyword";
$tag_list="keyword1,keyword2,keyword3";
?>
i want to generate site_title or tag_by_default from "folder name" then i can save time
i have many many pages to made
i have try something like this $tag_by_default="{page_title}";
but no result
if somebody can help me it would be great
Thank you carlos.
You'll need to make sure that the folder name does not have any spaces in it. Avoid underscores too, if you can.
You'll need to read that name, and strip out the word separators, changing them to spaces. You'll also need to Upper Case at least the first word.
The data will go to become the anchor text.
http://example.com/avril-lavigne-girlfriend/
i think i understand what you say but i don't know how to do it if you can give me example then i can make a batch file or something like that
thank you .
[edited by: dreamcatcher at 6:37 am (utc) on July 11, 2008]
[edit reason] use example.com. Thanks. [/edit]
FR:
Salut Carlos,
cherche dans Google, US version, pour la phrase comme elle est postee au dessus.
That's it, no more French for the day, let's use English :)
<edit>Typo</edit>
$filename = $_SERVER['SCRIPT_FILENAME'];
$fn = explode('/',$filename);
if(count($fn) >= 2) {
$tag_by_default = str_replace('-',' ',$fn[(count($fn)-2)]);
}
else {
$tag_by_default = str_replace('-',' ',$fn[0]);
}
before it was return this /avril-lavigne-girlfriend/index.php
and now it's like this avril lavigne girlfriend
so it's very good
i have anotther question in /avril-lavigne-girlfriend/index.php
i want it return only : avril lavigne
where is the code to be modified
this maybe : $fn = explode('/',$filename);
Do you always want the first two words?
Do you always want to exclude the last word?
You could use preg_match at the end, but writing regular expressions can be a little tricky. If you wanted the if you wanted the first two words you would do something like this:
preg_match('/^([a-z]+\s[a-z]+)/', $tag_by_default, $matches);
$new_tag = $matches[1];
But maybe a better way to do it, is to use explode() instead of str_replace.
Like:
if(count($fn) >= 2) {
$word_array = explode('-', $fn[(count($fn)-2)]);
}
else {
$word_array = explode('-', $fn[0]);
}
$tag_by_default = "$word_array[0] $word_array[1]";
$filename = $_SERVER['SCRIPT_FILENAME'];
$fn = explode('/',$filename);
if(count($fn) >= 2) {
$site_title = str_replace('-',' ',$fn[(count($fn)-2)]);
}
else {
$site_title = str_replace('-',' ',$fn[0]);
}
$filename = $_SERVER['SCRIPT_FILENAME'];
$fn = explode('/',$filename);
if(count($fn) >= 2) {
$word_array = explode('-', $fn[(count($fn)-2)]);
}
else {
$word_array = explode('-', $fn[0]);
}
$tag_by_default = "$word_array[0] $word_array[1]";
all is work and it's save me lot of time
because now i don't need to edit this file for other folder it's very good
i have last request
in my config file i have this
$site_url="mysite.com/avril-lavigne-girlfriend/";
i try to do something like this to replace the original by
$site_url=".";
it work on first page but after
when i clic on tag it done this problem >> mysite.com/avril-lavigne-girlfriend/tag/video and more i clic to another tag it continue like this
mysite.com/avril-lavigne-girlfriend/tag/video/tag/song....
so it's not good
maybe i forget something
original here :
$site_url="mysite.com/avril-lavigne-girlfriend/";
modified here:
$site_url=".";
if i want to do this it's for the same reason not reedit more 800 file for just change the adress hope you understand my meaning
thank you