Free Web Hosting Forum
(#1 (permalink))
Old
Member
nanotech is on a distinguished road
 
Posts: 41
Join Date: Apr 2012
Default need help for text string variable - 05-28-2012, 11:16 PM

i would like to know how to set up a variable text string from a resource file
like .dat or .txt

example

"today it was (a beautyfull) day"

need to be replace by "an awful"

"today it was (an awful) day"

i need to know how to setup a data file ( like .txt or . dat ) so that the string can be edited

from that file to update the other php or html files in a few different directorys

there must be some code for doing this

like the word awful from a .dat file be used to update that string in many others text related files

my primary use for that code would be to update first name and last name in at least 6 different php and or html files in a few different directorys


anyhelp appreciated

nano
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 733
Join Date: Dec 2010
Default 05-29-2012, 03:48 AM

Assuming that contact.txt file has columns for $firstname and $lastname,
and one line data are separated by tab, 2 variables can be updated by
getting data from contact.txt file as follows:

PHP Code:
<?php
$fp
=fopen("contact.txt","r");
while(!
feof($fp)) {
$contact=fgets($fp);    
list(
$firstname$lastname$email$phone) = explode("\t"$contact); 
$firstname trim($firstname);
$lastname trim($lastname);

echo 
"Firstname is $firstname.";
echo 
"Lastname is $lastname.";
}
?>
Reply With Quote
(#3 (permalink))
Old
Member
nanotech is on a distinguished road
 
Posts: 41
Join Date: Apr 2012
Default 05-29-2012, 03:52 PM

and this php code is it a stand alone php file that is within the public_html directory

or it does it need to be inserted in every files that i need those strings
Reply With Quote
(#4 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 733
Join Date: Dec 2010
Default 05-29-2012, 09:46 PM

The above code is just an example. You need to rewrite the code suitable for output, and the code
needs to be inserted in every file.

In your php or html files, if the output codes are calling data from your database, you need
to insert the data getting from .txt file into your database table. In other words, if you
insert/update the data in your table, 6 different files will also be updated accordingly
at once. The following example shows how to insert data getting from .txt file:

PHP Code:
<?php
$conn 
mysql_connect("mysql8.000webhost.com""a336xxxx_test","******") or die(mysql_error());
mysql_select_db("a336xxxx_test"$conn);

$fp=fopen("contact.txt","r");
while(!
feof($fp)) {
$contact=fgets($fp);    
list(
$firstname$lastname$email$phone) = explode("\t"$contact);
$firstname trim($firstname);
$lastname trim($lastname);

$sql "insert into table_name (firstname, lastname) values ('$firstname', '$lastname')"
$result mysql_query($sql); 
// if data are not inserted
if(!$result) echo "Database error!";
}
?>
Reply With Quote
(#5 (permalink))
Old
Member
nanotech is on a distinguished road
 
Posts: 41
Join Date: Apr 2012
Default 06-02-2012, 03:02 AM

i came up with some code like this one

file: names.php

<?php
$Text_1= "John";
$Text_2 = "bright";
$Text_3 = "monday";
$Url_1 = "example.net";
>



file: story.html

head

body

</php include 'names.php' ; ?>

This was "$Text_1"s birthday today a "Text_2" sunny "Text_3" a hot day it was.

body

head

i would like to know if the string would show up has there corresponding words
in the above text and would display like bellow

This was "john"s birthday today a "bright" sunny "monday" a hot day it was.


i did some test on a second file
for that form just to see what would happend


but it doesnt link me to the above url the file names.php

</php include 'names.php' ; ?>

<form method="post">
<input type="button" value="Your name"
onclick="location.href='$Url_1'">
</form>


sorry about my limited knowledge of web programming

those strings will be updated manually only once a while

any clues to what i am doing wrong
Reply With Quote
(#6 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 733
Join Date: Dec 2010
Default 06-02-2012, 04:20 AM

names.php
=========
PHP Code:
<?php 
$Text_1
"John";
$Text_2 "bright";
$Text_3 "monday";
$Url_1 'http://example.net';
?>
story.html
==========
Code:
<html>
<head>
<title>Variable Test</title>
</head>
<body>
<?php 
include 'names.php'; 
echo "This was \"$Text_1\"s birthday today a \"$Text_2\" sunny \"$Text_3\" a hot day it was.";
?>
</body>
</html>
link.php
========
PHP Code:
<?php
include 'names.php';
echo 
"<a href ='$Url_1'>example.net</a>";
?>
Reply With Quote
(#7 (permalink))
Old
Member
nanotech is on a distinguished road
 
Posts: 41
Join Date: Apr 2012
Default 06-02-2012, 10:39 PM

ok the story.php one works nice

but the link.php file doesnt with the onclick button

using the names.php reference file

<?php
include 'names.php';
echo "<form method=\"post\">
<input type=\"button\" value=\"Your name\"
onclick=\"location.href='$Url_1'\">
</form>
\n";
?>


is there an other way to do an external url from the button method with a $string for php code
Reply With Quote
(#8 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 733
Join Date: Dec 2010
Default 06-03-2012, 03:23 AM

link2.php
=========
PHP Code:
<html>
<head>
<script type="text/javascript"></script>
</head>
<body>
<?php include 'names.php';?>
<form>
<input type="button" value="Your name" onClick="location.href='<?php echo "$Url_1"?>'">
</form>
</body>
</html>
Reply With Quote
(#9 (permalink))
Old
Member
nanotech is on a distinguished road
 
Posts: 41
Join Date: Apr 2012
Default 06-07-2012, 11:56 PM

ok i found my problem

needed to include http:// for the href external url

ok now i would like to download a copy of my php.ini to my computer for back up in case i need it

is there a specific way to do so because i cant reach the /usr/local/lib/php.ini

file directly from the ftp server root directory in the file manager of the Cpanel
Reply With Quote
(#10 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 733
Join Date: Dec 2010
Default 06-08-2012, 03:15 AM

You are not allowed to directly access php.ini.

However, you can see php.ini setting with the following steps:

Go to your control panel - >>Software/Services - click 'View PHP Configuration'
Reply With Quote
Reply

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com