Page 1 of 1 [ 5 posts ] 

Albinoboy
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 5 Aug 2010
Age: 29
Gender: Male
Posts: 70
Location: Surrey, England

26 Aug 2010, 5:43 pm

OK, I know most of the code myself, however I don't know how to do the following:

1. Variables to file
So I have a config.php file like this:

Code:
/* Configuration */
$site="http://www.mysite.com";
$sitename="My Site";
$tagline="Is Awesome";


And I need to know how to change the variables via a control panel, as easily as possible.
Basically, site text box -> $site="contentsoftextbox"

2. List contents of folder and link to them
So
page.html
page/ignoreme.html
I need it to ignore subfolders
and page.html is linked to like this:
<a href="index.php?p=page" title="a page">Page</a>

3. Caps and Spaces
My script gets the title from the documents name, so:
this_page.html = this_page (it simply echos $page from the $_GET)
but I want it to look like this:
This Page

so all words start with a capitol and this "_" is replaced with this " "

Thx in advance!

EDIT: forgot to add ";" to the end of the variables... uh, or am I getting PHP mixed up with C? I have a headache, all of this coding I guess.



kra17
Veteran
Veteran

User avatar

Joined: 14 Feb 2010
Age: 31
Gender: Male
Posts: 594
Location: Sweden

26 Aug 2010, 6:25 pm

Albinoboy wrote:
3. Caps and Spaces
My script gets the title from the documents name, so:
this_page.html = this_page (it simply echos $page from the $_GET)
but I want it to look like this:
This Page

so all words start with a capitol and this "_" is replaced with this " "


ucwords($variable) to get the letters uppercase.

str_replace("_", " ", $variable) to replace "_" with " "

And yes, you should end stuff with ;


_________________
:bigsmurf: :bigsmurf:


Albinoboy
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 5 Aug 2010
Age: 29
Gender: Male
Posts: 70
Location: Surrey, England

26 Aug 2010, 7:10 pm

Thx, now that just leaves 1 & 2 left...

Google, you fail me, give me what I need!
No? Oh rats!



ari_
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 15 Sep 2009
Age: 35
Gender: Male
Posts: 65
Location: Netherlands

26 Aug 2010, 9:59 pm

Albinoboy wrote:
1. Variables to file
So I have a config.php file like this:
Code:
/* Configuration */
$site="http://www.mysite.com";
$sitename="My Site";
$tagline="Is Awesome";


And I need to know how to change the variables via a control panel, as easily as possible.
Basically, site text box -> $site="contentsoftextbox"


If you want to keep it simple and just for yourself: use the config file. If you want to learn new things and are prepared to invest time, try to make it work.

You can get your data via a form on your control panel. Example of a form:

Quote:
<form action="/index.php" method="post">
<input name="thingy" type="text" />
<input type="submit" />
</form>


Which will redirect to your homepage, called index.php. There you can access it via $_POST['thingy'], which is a variable. Check if it is set by calling isset($_POST['thingy'] (returns true if set, false if not). After that you can store the value in a file or database.

Remember to properly escape things, never trust user input. Strip any HTML (unless you need it) and properly escape anything that goes into a database. See a manual on how to store such things. That's simply too big to post here (especially since it is 5 AM here).

Albinoboy wrote:
2. List contents of folder and link to them
So
page.html
page/ignoreme.html
I need it to ignore subfolders
and page.html is linked to like this:
<a href="index.php?p=page" title="a page">Page</a>


I made something to do that, here is the translated code:

Quote:
//set directory
$dir = "placetostorethings";

//Checking files
if(is_dir($dir)) {
//valid directory, make handle
$handle = opendir($dir);
if($handle) {
//directory opened, make array
$array = array();

//put name of file in handle
$file = readdir($handle);
while(false != ($file = readdir($handle))) {
if($file != ".." && $file != "Thumbs.db") {
//for some reason it sees '..' (parent directory) as a file; ignore
//it also sees something called 'Thumbs.db'; ignore
//if it is anything else: put the name in the array
$array[] = $file;
}
}
closedir($handle);
//close handle

if(count($array) != 0) {
//if one of more files, sort them
sort($array);
echo "<h3>Files:</h3>";
foreach($array as $file) {
//walk through the array and list everything
echo '
<a href="'.$dir.'/'.$file.'" target="_blank">'.$file.'</a>
<br />
';
}
}
else {
echo 'No files found (directory: '.$dir.')';
}
}
else {
echo 'Failed to open directory '.$dir;
}
}
else {
echo 'Directory '.$dir.' does not exist';
}


You may need to change the link, I don't 'get' the way you link. Then again, it's pretty early here. I probably get it when I wake up.

Sorry for the bad formatting, the forum does not recognize tabs. I hope you find it useful.



Albinoboy
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 5 Aug 2010
Age: 29
Gender: Male
Posts: 70
Location: Surrey, England

26 Aug 2010, 10:39 pm

Thx, very helpful
As of the way I link:

Code:
$_GET['p']=$page;

And later in the code:
Code:
include("pages/".$page.".html");

So content is separate from design.

I will use that read directory code to check the contents of "pages/" and make a navbar from them.
Then for my sub-navigation, all files in a folder that has the same name as the page then that will be put into a sidebar.

So home may have no subpages at all, and so only the main navbar is displayed, but about have several subpages, and so it shows a sidebar, and if their is subpages to those subpages, yeah, you get my point.