Current location: Hot Scripts Forums » Programming Languages » PHP » get vars from local file into textareas


get vars from local file into textareas

Reply
  #1 (permalink)  
Old 07-13-03, 06:34 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
get vars from local file into textareas

Hello,

How would I go about getting the content of 4 variables from various local files and into a form so they can be edited?

There is other PHP code in these files that I do not want to be processed - I just want the variables contents to be put into each textarea.

I want the PHP page to print out each variable something like this:

PHP Code:

print "<textarea name=page cols=\"95\" rows=\"13\" wrap=\"VIRTUAL\" class=\"box\">".$content."</textarea>"
Thanks - Paul
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-13-03, 06:44 AM
SleeperZ SleeperZ is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
How exactly would the variables in these files change?

I guess what im asking is, why do you need to include them from 4 diff files if they're always gonna be the same?

What I would do if they are always gonna be the same, but used in different files:

1 File - config.php - put ya 4 variables here.
4 Files - include("config.php");

Other Files requiring these Vars - include("config.php");
__________________
***Expect the Unexpected***
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-13-03, 07:05 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry for the lack of clarity on that! The variables represent the
changing content for each page of my site. Every page has the
same variables but with different contents to them.

Here is what I am attempting in my newbie-half-baked way.
Every page on my small site is composed of 4 variables: $content, $bodybg, $lcolpad and $title.

example page code for my /experience/index.php page
might look like this:

PHP Code:

$content '<div id="title">

<script language="JavaScript" type="text/javascript" src="/_includes/js/h1_experience.js"></script>
<noscript><img src="/_images/titles/experience.gif"></noscript>
<h1>%metaDesc%</h1></div>

<p>
I have done all sorts of work for different blah blah blah etc etc </p>'
;

$bodybg 'none';
$lcolpad '40';
$title 'Experience in show business';

/*code below that I do not want to be processed on my forms 
page but is necessary on each web page to "pull" the html 
template and a few other functions and combine with my above 
variables so I can output a real html page to the site visitor*/

$dir getcwd();
$os substr_replace($dir''2);
if (
$os == "J:") {$osRoot "J:/Apache2/htdocs/";}
else {
$osRoot "/home/domain/public_html/";}

/* contains code to file_get_contents of html template and substr_replace 
things like %content% with $content etc*/
include ($osRoot."_includes/php/logic_pre_html.inc.php");
?> 

I am trying to learn how to make a simple cms tool where you
type in the URL of a file on my server, press submit and up comes a form with 4 textareas, each displaying one of the variables. You can re-type the stuff and press save and it then rewrites the old
page with the new variables contents. I know other people have done this better and the site is so small I dont really need a PHP
form to edit pages cuz' there are only about 15 pages total anyway. It's basically a learning tool for me.

Anyhow when I include(); a page it not only puts the variables into each textarea (yay!) but it also process the code on the bottom and ends up displaying the entire html template and all (bad...).

Thanks for your reply SleeperZ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-13-03, 07:59 AM
tai fu's Avatar
tai fu tai fu is offline
me
 
Join Date: Jul 2003
Location: Greece
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Here it is how i "dream" it..

Put 4 .php files with your info , like this:
<?php
$contentbg = 'something';
$...... = ...;
...
...
?>

then when you want to retrieve the info just include it.. and then when you want to change it :
f= 'directory/file.php';
fopen...
fwrite("<?php $contenbg =' ".$newcontentbg." '; blabla ?>");
...
...
(where $newcontentbg will be the new data iserted)

Hope you understood...
__________________
let my source be on your side...
<a href="http://www.programersguild.com">Programer's Guild</a><a href="http://gcf.linuxserver.at">Gnome Code factory
</a>

Last edited by tai fu; 07-13-03 at 08:01 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-15-03, 12:47 AM
ridwank's Avatar
ridwank ridwank is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Indonesia
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
TRY THESE
I HOPE IT WAS WHAT YOU NEED...

<?
$myfile="help.txt";

if ($btupdate=="UPDATE"){
$file=fopen($myfile,"w");
$newcontent=stripslashes($newcontent);
fputs($file,$newcontent);
fclose($file);
echo "<h3>FILE $myfile HAS BEEN UPDATED</h3>";
}


if($file=fopen($myfile,"r"))
{
$linenum=0;
while(!feof($file))
{
$contents.=fgets($file,255);
$linenum++;
}
fclose($file);
}
else
{
echo("File not Found");
}

echo "<FORM METHOD=\"post\" ACTION=\"".$PHP_SELF."\">";
echo "<p>Content File : $myfile</p>";
echo "<p><TEXTAREA NAME='newcontent' cols=60 rows=20 class=entri>".$contents."</TEXTAREA>";
echo "<p><INPUT TYPE=submit NAME='btupdate' VALUE='UPDATE' class=tombol> ";
echo "<INPUT TYPE=reset VALUE='RESET' class=tombol> ";
echo "</FORM>";

?>
__________________
-=ridwank=-

<b><a style='text-decoration:none' href="http://www.ridwank.com">CLICK : ridwank.com : PHP SCRIPT CENTER</a></b>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-15-03, 02:02 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Hey you guys rock!

Ridwank, that was the answer to my dilemna. Now I have 2 things to make sure I can do.
1 - If I have double quotes in my variables like <img src="1.gif"> I have to escape with backslash -- no problem though.
2 - I have to figure out why this worked!!

Thanks again, yesterday I made my first while () loops work and today I have this to go with -- PHP is great!

- Paul
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing file to local machine. cunger28 PHP 1 09-30-03 07:29 PM
New Web Host, New Problem! justchat PHP 2 09-29-03 03:39 PM
Writes to a text file gamextremer2003 JavaScript 4 09-11-03 10:43 AM
Upload file type and size limiter! Arctic ASP 1 08-02-03 08:06 PM
how to get info from TXT file between %%customTags%% as vars?? paulj000 PHP 2 07-26-03 06:00 AM


All times are GMT -5. The time now is 07:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.