hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP Question. -- Text.
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP Question. -- Text.

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 04-02-2003, 06:25 PM
aingaran aingaran is offline
Web Hosting Master
 
Join Date: Oct 2000
Location: Toronto
Posts: 1,103

PHP Question. -- Text.


Hi everyone,

I was wondering if it's possible to do this.

Some value is returned in text format after performing something.

Example, a text file is returned containing just this.
(without the ---)
------------------------------------
THE_ANSWER=10
------------------------------------

From that text file, (using some other script obviously)
Is it possible to do this?

PHP Code:
if ($the_answer=="10")
{
do 
this
}
else
{do 
something else.

So, in essence, making 'THE_ANSWER' into a variable from the text file.

It doesn't have to be a text FILE.
It can be just text that is returned, in the browser. (file not created, text just diplayed)

I hope you understand my gibberish

Thanks,

Reply With Quote


Sponsored Links
  #2  
Old 04-02-2003, 06:50 PM
null null is offline
Web Hosting Master
 
Join Date: Sep 2002
Location: Illinois
Posts: 2,305
Just wrote and tested the program. Works good. This code will work only with the first line of the file.

PHP Code:
<?php

    
    error_reporting 
(0);
 
 
/* the file we will open */

     
$file 'file.txt';
    
 
/* read the file into the array $content */

     
$content file ($file);


    
/* split the first line of the file to THE_ANSWER and 10 */
    
    
$line split ('='$content[0]);


/* delete spaces */    
    
    
while (list($key$value)=each($line))
        
$line[$key] = trim ($value);

    
/*  
    Make_THE ANSWER as a variable 
    using the Variable variables feature 
    in PHP and assign it the value that 
    comes after equal symbol in file 
*/

     
$$line[0] = $line[1];

    echo 
$THE_ANSWER;


?>

Reply With Quote
  #3  
Old 04-02-2003, 08:14 PM
jb4mt jb4mt is offline
Aspiring Evangelist
 
Join Date: Dec 2002
Location: Georgia
Posts: 419
null's has the advantage that he tested it. mine is off the top of my head, but, should it prove feasible, has the advantage of being briefer.

Just slap a "var $" onto the front and eval it. Oh yeah, with a semi-colon on the end and quotes around it.

truthfully null's might be a better idea. in either case, you get to work with concepts such as a "variable variable" as he mentioned, or, in my case, eval().

Reply With Quote
Sponsored Links
  #4  
Old 04-02-2003, 08:15 PM
aingaran aingaran is offline
Web Hosting Master
 
Join Date: Oct 2000
Location: Toronto
Posts: 1,103
Thank you sooo much!!

Another question.

The script is for a file..

Is it possible to do the samething with content returned INTO broswer, instead of a text file?

Thanks,

Reply With Quote
  #5  
Old 04-02-2003, 08:29 PM
Gamenati Gamenati is offline
Temporarily Suspended
 
Join Date: Jan 2003
Posts: 160
umm, you mean form?

PHP Code:
<html>
<
body>
<
form method="get" action="/nextpage.php">
<
input type="text" name="words">
<
input type="submit">
</
form>
</
body>
</
html
/nextpage.php
PHP Code:
<?php
echo $words ;
?>
if thats what you mean...

Reply With Quote
  #6  
Old 04-02-2003, 08:50 PM
aingaran aingaran is offline
Web Hosting Master
 
Join Date: Oct 2000
Location: Toronto
Posts: 1,103
well, from nextpage.php

whatever is echo'd. It'll be in a text form.

I'd like to changed the echo'd text into a variable.

page.php
<?

echo "Answer = 1";

?>

Now, from page.php

I'd like to do the following:
change 'Answer' into $answer so that I can do this:

if ($answer=="1")
{do something}
else
{do something else}

Reply With Quote
  #7  
Old 04-03-2003, 04:37 AM
xerocity.com xerocity.com is offline
Junior Guru
 
Join Date: Apr 2002
Location: Sacramento, CA
Posts: 220
Here you go:

page.php

PHP Code:

<?

// I removed "Answer = " because it makes it easier to process

echo '1';

?>

processresult.php
PHP Code:

<?php

$url 
'http://www.yourwebsiteaddress.com/pagewithvariable.php';

$answer file($url);

if (
$answer[0] == '1') {
    echo 
'Variable equaled one';
}
else {
    echo 
'Variable did not equal one';
}

?>
I am assuming that you will have page.php on one server and processresult.php on another as it would be the only reason to do it this way.

Also the example above is only set to accept one variable; the single variable must also be on the first line for this to work.

__________________
Joel Strellner

Reply With Quote
  #8  
Old 04-03-2003, 04:52 AM
xerocity.com xerocity.com is offline
Junior Guru
 
Join Date: Apr 2002
Location: Sacramento, CA
Posts: 220
Now that I reread null's post and looked at mine, there really isn't much difference.

Sorry null if it looks like I was copying your post.

aingaran, the "file" function can load local or remote files.

__________________
Joel Strellner

Reply With Quote
  #9  
Old 04-03-2003, 08:17 AM
null null is offline
Web Hosting Master
 
Join Date: Sep 2002
Location: Illinois
Posts: 2,305
no problem, it's open source

Reply With Quote
  #10  
Old 04-03-2003, 11:46 AM
aingaran aingaran is offline
Web Hosting Master
 
Join Date: Oct 2000
Location: Toronto
Posts: 1,103
Guys,

I couldn't thank you enough for your efforts.

But, I haven't explained the scenario properly.

A file will not be created.

I just used the file as an example.

I have a script..Which would do something on another server.
The other server will return some sort of response in text form. (a file will not be created.)

I'd like to take the response from the other server, and convert some of it into variables.

Thanks,

Reply With Quote
  #11  
Old 04-03-2003, 11:52 AM
xerocity.com xerocity.com is offline
Junior Guru
 
Join Date: Apr 2002
Location: Sacramento, CA
Posts: 220
Quote:
Originally posted by aingaran
Guys,

I couldn't thank you enough for your efforts.

But, I haven't explained the scenario properly.

A file will not be created.

I just used the file as an example.

I have a script..Which would do something on another server.
The other server will return some sort of response in text form. (a file will not be created.)

I'd like to take the response from the other server, and convert some of it into variables.

Thanks,
I believe that the solution to your problem can be solved by utilizing the code that I provided above. It allows for the scenario you are speaking of.

__________________
Joel Strellner

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
WHD.global 2013: Open-Xchange Launches Browser-based Office Productivity Suite Web Hosting News 2013-03-20 06:55:56
Are you ready for Speed Networking at WHIR Events? Blog 2013-01-18 07:00:04
Irish Web Host LetsHost Sending Billing Reminders to Customers via Text Message Web Hosting News 2012-03-13 17:00:48
Rackspace Blog Looks at Easy Outsourcing for App Development Blog 2012-03-05 19:07:48
Landing Page Practices to Improve Marketing ROI with Tim Ash of SiteTuners Web Hosting News 2011-08-09 22:20:06


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?