Hi there
I currently have a .txt file (lets call it jimharper.txt) that holds a
number of arrays like for instance:
$name[] = "Jim Harper"
$relatives[] = "Joan Harper (wife)"
$relatives[] = "Beth Harper (daughter)"
$occupation[] = "Police officer"
$occupation[] = "Teacher"
That I need to be imported into another file (profile.php) so that when
I open profile.php?nam e=jimharper it extracts the information from the
jimharper.txt file which resides in a different directory.
So the output in the profile.php?nam e=jimharper would be something like:
Name: Jim Harper
Relatives: Joan Harper (wife), Beth Harper (daughter)
Occupation: Police officer, Teacher
I can figure out how to do it if the arrays were in the same file as the
code but it's not.
I've tried all sorts of things but by now my coding is such a big mess
that I'd rather not share it as it would probably only confuse matters.
Anybody have any ideas?
Kim Jensen 13 1577
Can you just include the txt file in your profile.php? Something like:
$file = "/path/to/file/" . $name . ".txt";
require($file);
rich wrote: Can you just include the txt file in your profile.php? Something like:
$file = "/path/to/file/" . $name . ".txt"; require($file);
As far as I can see that includes the entire .txt file in the .php page.
I "only" need it to extract the information in the arrays in the .txt
file and sometimes not even all of the arrays. I have two .php files
that extract different (and in some cases some of the same) information
from the .txt file.
Kim Jensen
Ah I didn't realize that would be a problem. The only thing I can
think of, and this is a TOTAL guess, but
Open file
while reading file
if the line starts with a var that i want ($name)
eval() the line
Got it. I made the below just check the first 3 chars of a line... you
can change it to check the line however..
Text file contains:
$foo = "bar";
php file has:
$file = "file.txt";
$fp = fopen($file, "r");
while (!feof($fp)) {
$line = fgets($fp, 1024);
$FirstThree = substr($line, 0, 3);
if ($FirstThree == "\$fo") {
eval($line);
echo $foo;
}
}
The above returns "bar"
rich wrote: Got it. I made the below just check the first 3 chars of a line... you can change it to check the line however..
Seems to be working. I don't understand the need for the line-checking
though. Shouldn't it be possible to just ask it to get the $foo-array
once the file has been opened?
Kim Jensen
Text file contains:
$foo = "bar";
php file has:
$file = "file.txt"; $fp = fopen($file, "r"); while (!feof($fp)) { $line = fgets($fp, 1024); $FirstThree = substr($line, 0, 3); if ($FirstThree == "\$fo") { eval($line); echo $foo; } }
The above returns "bar"
Kim Jensen wrote: rich wrote:
Got it. I made the below just check the first 3 chars of a line... you can change it to check the line however..
Seems to be working. I don't understand the need for the line-checking though. Shouldn't it be possible to just ask it to get the $foo-array once the file has been opened?
Kim Jensen
Text file contains:
$foo = "bar";
php file has:
$file = "file.txt"; $fp = fopen($file, "r"); while (!feof($fp)) { $line = fgets($fp, 1024); $FirstThree = substr($line, 0, 3); if ($FirstThree == "\$fo") { eval($line); echo $foo; } }
The above returns "bar"
Kim,
Opening a file does not process it - all it is is a bunch of text. So
foo-array doesn't exist. Rich is correct - you need to eval() the lines
to make it work.
However, I think this would be a lot easier with a database!
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
Jerry Stuckle wrote: Opening a file does not process it - all it is is a bunch of text. So foo-array doesn't exist. Rich is correct - you need to eval() the lines to make it work.
Ok. I get it.
However, I think this would be a lot easier with a database!
Probably. It's just that I have thousands of files and turning them into
a database would probably take me forever as I don't know of any easy
ways of doing so.
Kim Jensen
Kim Jensen wrote: Jerry Stuckle wrote:
Opening a file does not process it - all it is is a bunch of text. So foo-array doesn't exist. Rich is correct - you need to eval() the lines to make it work.
Ok. I get it.
However, I think this would be a lot easier with a database!
Probably. It's just that I have thousands of files and turning them into a database would probably take me forever as I don't know of any easy ways of doing so.
Kim Jensen
Kim,
Yep, it is a chore. But next year you'll have even more files to
convert. And you'll still be spending time manually keying things like
this in, checking for errors, etc.
A database can really help. Perhaps you can automate the processing of
the files with a program?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
Jerry Stuckle wrote: Yep, it is a chore. But next year you'll have even more files to convert. And you'll still be spending time manually keying things like this in, checking for errors, etc.
I know. However I have next to no experience with working on databases
but know a bit of php so for now doing it like this seems easier. Right
now my main .php script looks like this:
-----
if ($_GET["name"]) {
$lines = explode("\n",fi le_get_contents ("Who/" .
strtolower($_GE T["name"]) . ".txt"));
foreach ($lines as $item) {
if ($item != "") {
$parts = explode("=",tri m($item),2);
$item_vars[$parts[0]] = $parts[1];
}
}
-----
and then I retrieve the information using stuff like
echo $item_vars["occupation "]
echo $item_vars["occupation 2"]
from a file that has:
occupation=Poli ce officer
occupation2=Tea cher
The code end up looking like shit when I have to add for instance up to
echo $item_vars["occupation 20"] so I was looking for an easier way to do
it, so that I didn't have to make sure the .php page always had as many
echo's as the .txt pages had $item_vars
I know a database would probably be the best way to get things organized
but until I figure out how to configure one for what I need I just
wanted to clean up my php.
A database can really help. Perhaps you can automate the processing of the files with a program?
Do you know of any programs that can do that or know where I can look
for some? Considering everything is in .txt files at the moment I would
guess it would be easy turning them files into something that could
easily be converted after a couple of search/replaces or something.
Kim Jensen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dariusz |
last post by:
I want to use arrays in my website (flat file for a guestbook), but despite
having read through countless online tutorials on the topic, I just can't
get my code to work.
I know there are guestbook scripts out there - but that doesn't help me
learn how to programme arrays !!!
The following is the code for the PHP (called externally), which does
execute...
|
by: da Vinci |
last post by:
OK, this has got to be a simple one and yet I cannot find the answer
in my textbook.
How can I get a simple pause after an output line, that simply waits
for any key to be pressed to move on?
Basically: "Press any key to continue..."
I beleive that I am looking for is something along the lines of a....
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
Hello,
I have a very simple problem but cannot seem to figure it out. I have a
very simple php script that sends a test email to myself. When I debug
it in PHP designer, it works with no problems, I get the test email. If
|
by: Mingus Tsai |
last post by:
Hello- please help with unpickling problem:
I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows
XPhome system.
My problem is with using cPickle to deserialize my pickled arrays of
datetime.datetime instances. The following is the code I have written:
import cPickle, datetime
import Numeric
|
by: bobmct |
last post by:
Fellow PHP'ers;
I'm digging myself a hole on this one so I thought it has come to the
time when I must ask those who know.
I have what should be a simple question for loading, accessing and
retrieving values stored in a simple one-dimensional array.
I am simply trying to determine the occurrence of numbers as they
appear in a file. For example lets assume the lowest allowed value is
| |
by: Rex |
last post by:
Hi All - I have a question that I think MIGHT be of interest to a
number of us developers. I am somewhat new to VIsual Studio 2005 but
not new to VB. I am looking for ideas about quick and efficient
navigating within Visual Studio 2005. Let's say your project (or
solution) has dozens of forms and hundreds or even thousands of
routines.
Two Questions:
1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
|
by: Jay |
last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send
text messages to many, many employees via system.timer at a 5 second
interval. Basically, I look in a SQL table (queue) to determine who needs
to receive the text message then send the message to the address. Only
problem is, the employee may receive up to 4 of the same messages because
each thread gets the recors then sends the message. I need somehow to
prevent...
|
by: weidongtom |
last post by:
Hi,
I've written the code that follows, and I use the function add_word(),
it seems to work fine
*before* increase_arrays() is called that uses realloc() to allocate
more memory to words. But *after* calling increase_arrays(), I
received segmentation fault. I tried to step it through gdb, and I
found out that after calling increase_arrays(), words's original
value is modified, and if I tried to access it, I get <address 0x11
out of...
|
by: ndedhia1 |
last post by:
I am reading in a file to see what delays I am getting on what IP address:
QuoteBlockTiming exceeded 1000 ms: 1684 --- Fri Nov 06 06:09:10 CST 2009 170.137.94.95 Class key = 649126730 block size = 1 session = W_MAIN
QuoteBlockTiming exceeded 1000 ms: 1640 --- Fri Nov 06 06:09:18 CST 2009 170.137.94.2 Class key = 649126749 block size = 1 session = W_MAIN
QuoteBlockTiming exceeded 1000 ms: 1146 --- Fri Nov 06 06:28:25 CST 2009 170.137.88.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |