Solved

PHP

Posted on 2003-10-28
5
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

717 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