Solved

How to change two parameters in a PHP file?!

Posted on 2008-06-12
4
215 Views
Last Modified: 2008-06-19
Hello group,

I'm writing a small web application which allows a user to upload a game (Flash base). Let's say user uploads a file called game.swf
On the fly, the code creates a game.php associated to the game. So now we have:
1) game.swf
2) game.php files on server.

The generated PHP file is a page and it also has the <embed> tag injected in it. Of course, it has two parameters as WIDTH and HEIGHT which specify the dimension of the game. So far, I don't have any issue.

The problem is that if the game owner decides to apply changes (such as name, description and etc) it works fine but I don't know how to change the width and height parameters which already are hard coded in the generated PHP file.

Is there any function that let me to change two or more values in an existing PHP/HTML file?

Any suggestions or advice will be appreciated.

Regards.
0
Comment
Question by:akohan
  • 2
4 Comments
 
LVL 4

Assisted Solution

by:afzz
afzz earned 100 total points
ID: 21772683
If the file is not too big use the file() function to read the file into an array, loop through the array to find what you want to change while saving the rest into another variable when you come acroos the values to change, save the changed values into the new variable and finally write it back to the file

0
 

Author Comment

by:akohan
ID: 21772751

Yes, it is small. I will give a try.

Thanks!
0
 
LVL 5

Accepted Solution

by:
pbeirne earned 400 total points
ID: 21772772
You could keep the width and height parameters in an include file or stored in a mySQL database rather than hard coding them in your page.  Then your application's update routine could update or replace the include file or mySQL and your PHP page wouldn't have to be modified.
0
 

Author Comment

by:akohan
ID: 21825693

Both methods were fine but the latter gave me more flexiblity.

Thanks to all.
Regards.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

825 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