Solved

PHP

Posted on 2003-10-28
5
295 Views
Last Modified: 2010-04-07
Hi everyone, I hope this is an easy one – I would simply like to combine a bunch of PHP functions into one script.  Here is the architecture:

1) I send a PHP script a series of variables that have a value.  If these variables have a value, PHP fires a script:

varA=1
varB=2
varC=3
varD=4
…and so on (a total of 30 variables in sequential order)

2) If varA = ‘something’ then do the following:
<?
$file = fopen("./Folder/" . "NewFile1", "w");
fwrite($file,"$varA");
fclose($file);
?>

If varB = ‘somehting’ then do the following:
<?
$file = fopen("./Folder/" . "NewFile2", "w");
fwrite($file,"$varB");
fclose($file);
?>

This is repeated all the way down to the 30th variable.

Hope this is easy.
0
Comment
Question by:Donavan_usa
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
mleeb earned 400 total points
ID: 9648776
1. Simply form an array of the variables.
2. Obtain the length of the array.
3. Run a for loop on the array of variables.
4. Test that the current variable has a value.
5. Perform file creation function.
6. Continue looping until complete.

$varA = 1;
$varB = 2;
$varC = 3;

$arrayName = array ($varA, $varB, $varC);
$arrayLength = count($arrayName);

for ($i = 0; $i < $arrayLength; $i++)
{
     if($arrayName[$i] != '')
     {
      $file = fopen("Folder/NewFile$arrayName[$i]", "w");
      fwrite($file, "$arrayName[$i]");
      fclose($file);
     }
}
?>  
0
 

Author Comment

by:Donavan_usa
ID: 9651109
Thanks mleeb, I will try out your above code.

Cheers.
0
 

Author Comment

by:Donavan_usa
ID: 10416468
Sorry for delay - what if there is an unlimited number of variables coming in?

Cheers
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now