Solved

How to change two parameters in a PHP file?!

Posted on 2008-06-12
4
227 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 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