babyoh Posted March 13, 2006 Share Posted March 13, 2006 i want to make changes to my webpages via PHP includes, so i don't have to change each page separately. -- i have 20 directories, each with an index.html, each named the same name as the directory.so, i'll have paths like: mywebsite.com/canada, mywebsite.com/unitedstates, etc.i want the canada page to have a line in it: "hello from canada," the us one to say "hello from the united states," etc. (not all the text is identical except for locale). * i've tried everything i can think of, but can't get this to work.- i'd also like to have the ENTIRE PHP SECTION as an INCLUDE, so that i can delete/edit etc. * main problem is doing an include with a $place variable that tells PHP that the variable is declared in the FILE THAT'S CALLING IT. * i'm thinking i need a <?php include "http://mywebsite.com/1.php"; ?> inside my WASHINGTON file (mywebsite.com/washington). AND that include says something like:<? $locale = ucwords(basename(dirname(__FILE__))); echo "Hello from $place"; ?> *i'm new to PHP; i tried a bunch of other things that DIDN'T work. (other, simple PHP includes work fine, but this is more complicated: an include will only pull my IOWA $place variable as Iowa if it's within the same file or folder as the Iowa directory - which defeats the purpose: i want to make ONE change ONCE, and have it effect all my pages.)- thanks for anyone who can help Quote Link to comment https://forums.phpfreaks.com/topic/4806-php-question-cant-figure-this-out/ Share on other sites More sharing options...
fusionpixel Posted March 13, 2006 Share Posted March 13, 2006 I would like to help but I cant understand your request.. I read IOWA and USA and Canada... its too confusing.Could you narrow down your question and if you have some code that you are working with currently that might help too!:)oh! btw there is a templating tutorial in this website:[a href=\"http://www.phpfreaks.com/tutorials/8/0.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/8/0.php[/a]its not a recent tutorial but it sure will get you started. Quote Link to comment https://forums.phpfreaks.com/topic/4806-php-question-cant-figure-this-out/#findComment-16927 Share on other sites More sharing options...
babyoh Posted March 13, 2006 Author Share Posted March 13, 2006 sorry... let me try again:i want "hello from hawaii" (without quotes) to appear on my page that has the path mywebsite.com/hawaiii want "hello from utah" to appear on my page located at mywebsite.com/utahand i (MAY) want "the weather in idaho" on my index.html at mywebsite.com/idahofrom WITHIN the /hawaii file above, it works for me to use php that declares the $place variable as "hawaii" and have code like this in the index.html:<? $place = hawaii;echo "hello from $place"; ?> - BUT this means i need to insert the SAME code, substituting "utah" as the variable $place in the utah file, "canada" as the $place variable in the canada file, etc etc. ** (i actually have a great many more files than just 2 or 3, which is why using includes will be so much easier) **- i'd like to use an external include, so i can change significant portions of my pages regularly (it's much more work for me to make changes, if everything is HTML on the pages themselves) ** SO... i THINK this is what i need to do...from WITHIN my texas file, i declare the $place variable as texas:<? $place = texas ?>THEN, i want to have an include that would look like: <?php include "http://mywebsite.com/1.php"; ?> - inside include1.php i might have code looking like:<? echo "hello from $place;"> - - BUT this doesn't work, because PHP doesn't know how to find the $place variable (which needs to change, depending on which file is calling the code.) ** i need a "path" telling PHP to pick up the $place variable FROM THE FILE THAT'S CALLING IT)so that:in my utah page, this include prints to screen as "hello from utah",AND "hello from canada" is printed in the canada page, from the very same include -- i need the include to retrieve $place from "mywebsite.com/<LOOK IN THE FILE REQUESTING THIS CODE FOR THE $PLACE VARIABLE">- in my mywebsite.com/maine html file, i want to use: <?php include "http://mywebsite.com/1.php"; ?>and have the MAINE page read: "hello from maine"- in my mywebsite.com/honolulu html file, i want to use: <?php include "http://mywebsite.com/1.php"; ?>and have the MAINE page read: "hello from honolulu" - am i making this clear? -another example might be 20 pages with the SAME link, only substituting "utah dating" in utah page, "ohio dating" on the ohio page, etc.***you may have another way of doing this, but with my limited understanding of PHP, this is what i came up with.i can change large sections of page text by using PHP includes, but i'd like to MODIFY those includes so they pick up VARIABLES from the page that calls them...now, it just happens that each DIRECTORY is NAMED the variable that i want to use - the index.html file in mywebsite.com/wyoming has "Wyoming" as $place.i was trying to set the $place variable in the include by using dirname, basename, etc. but i was either getting "hello from public_html" (the main directory that mywebsite.com/maine sits in, or "hello from" and blankspace.***hope i've explained it this time.(and thankx for your help):) Quote Link to comment https://forums.phpfreaks.com/topic/4806-php-question-cant-figure-this-out/#findComment-16951 Share on other sites More sharing options...
babyoh Posted March 13, 2006 Author Share Posted March 13, 2006 sorry... let me try again:i want "hello from hawaii" (without quotes) to appear on my page that has the path mywebsite.com/hawaiii want "hello from utah" to appear on my page located at mywebsite.com/utahand i (MAY) want "the weather in idaho" on my index.html at mywebsite.com/idahofrom WITHIN the /hawaii file above, it works for me to use php that declares the $place variable as "hawaii" and have code like this in the index.html:<? $place = hawaii;echo "hello from $place"; ?> - BUT this means i need to insert the SAME code, substituting "utah" as the variable $place in the utah file, "canada" as the $place variable in the canada file, etc etc. ** (i actually have a great many more files than just 2 or 3, which is why using includes will be so much easier) **- i'd like to use an external include, so i can change significant portions of my pages regularly (it's much more work for me to make changes, if everything is HTML on the pages themselves) ** SO... i THINK this is what i need to do...from WITHIN my texas file, i declare the $place variable as texas:<? $place = texas ?>THEN, i want to have an include that would look like: <?php include "http://mywebsite.com/1.php"; ?> - inside include1.php i might have code looking like:<? echo "hello from $place;"> - - BUT this doesn't work, because PHP doesn't know how to find the $place variable (which needs to change, depending on which file is calling the code.) ** i need a "path" telling PHP to pick up the $place variable FROM THE FILE THAT'S CALLING IT)so that:in my utah page, this include prints to screen as "hello from utah",AND "hello from canada" is printed in the canada page, from the very same include -- i need the include to retrieve $place from "mywebsite.com/<LOOK IN THE FILE REQUESTING THIS CODE FOR THE $PLACE VARIABLE">- in my mywebsite.com/maine html file, i want to use: <?php include "http://mywebsite.com/1.php"; ?>and have the MAINE page read: "hello from maine"- in my mywebsite.com/honolulu html file, i want to use: <?php include "http://mywebsite.com/1.php"; ?>and have the MAINE page read: "hello from honolulu" - am i making this clear? -another example might be 20 pages with the SAME link, only substituting "utah dating" in utah page, "ohio dating" on the ohio page, etc.***you may have another way of doing this, but with my limited understanding of PHP, this is what i came up with.i can change large sections of page text by using PHP includes, but i'd like to MODIFY those includes so they pick up VARIABLES from the page that calls them...now, it just happens that each DIRECTORY is NAMED the variable that i want to use - the index.html file in mywebsite.com/wyoming has "Wyoming" as $place.i was trying to set the $place variable in the include by using dirname, basename, etc. but i was either getting "hello from public_html" (the main directory that mywebsite.com/maine sits in, or "hello from" and blankspace.***hope i've explained it this time.(and thankx for your help):) Quote Link to comment https://forums.phpfreaks.com/topic/4806-php-question-cant-figure-this-out/#findComment-16962 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2006 Share Posted March 13, 2006 Take a look at the functions pathinfo() and basename(). By using a combination of those functions you should be able to get the directory name to use in your script.BTW, you will either have to rename all of the index.html files to index.php or tell your webserver to process HTML files as PHP.Ken Quote Link to comment https://forums.phpfreaks.com/topic/4806-php-question-cant-figure-this-out/#findComment-16965 Share on other sites More sharing options...
babyoh Posted March 13, 2006 Author Share Posted March 13, 2006 -doesn't work.-i need code that tells PHP to FIND THE FILE THAT'S CALLING IT.the only way i can figure out how to make pathinfo () work, is to declare the path, like:<?php$path_parts = pathinfo('/www/htdocs/index.html');echo $path_parts['dirname'], "\n"; ?>* i need code that says:$pathinfo ('/index.html/(THIS IS WHERE YOU WANT TO GO; THE NAME WILL CHANGE - IT'S WHATEVER IS CALLING FOR THE VARIABLE)(since the name of that DIRECTORY and $variable happen to be the SAME, i can either call the DIRECTORY NAME O_R a Variable declared in the index.html file there... i would rather do that latter, so this will be more helpful for me later)--- also, i'm parsing, so my PHP shows in .html files; no problems there Quote Link to comment https://forums.phpfreaks.com/topic/4806-php-question-cant-figure-this-out/#findComment-17184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.