TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-27-2009, 04:55 PM   #1 (permalink)
The Contributor
 
webosb's Avatar
 
Join Date: Nov 2007
Posts: 41
Thanks: 24
webosb is on a distinguished road
Default need help on editing php files with arrays with php

not sure if this is the most efficient way of doing this but i have a file called myData.php that has the following:

PHP Code:
<?php
$data 
= array(
                array(
                    
"theURL" => "http://www.google.com",
                    
"title" => "Google",
                    
"someText" => "Google Search Engine",
                    
"moreText" => "Google Search Engine. Find whatever you want on the web.",
                    
"thumbnail" => "tn_google.jpg"
                
),

                array(
                    
"theURL" => "http://www.yahoo.com",
                    
"title" => "Yahoo",
                    
"someText" => "Yahoo Search Engine",
                    
"moreText" => "Yahoo Search Engine. Find whatever you want on the web.",
                    
"thumbnail" => "tn_yahoo.jpg"
                
),

                array(
                    
"theURL" => "http://www.msn.com",
                    
"title" => "MSN",
                    
"someText" => "MSN Search Engine",
                    
"moreText" => "MSN Search Engine. Find whatever you want on the web.",
                    
"thumbnail" => "tn_msn.jpg"
                
),                
);
?>
so I want to create a web interface to edit those values so i dont have some random person editing it and breaking it. So what is the best route for accomplishing this. Should I be using file_get_contents? or is there something better?
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
webosb is offline  
Reply With Quote
Old 01-27-2009, 10:45 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I don't think I understand. Couldn't you just pass in 2 arguments:

Argument 1: param=0/title
Argument 2: Froogle


That will then update the item in the array which argument 1 points to, with the data in argument 2. Please elaborate though, because I think your question is a little more complex than that.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-29-2009, 03:33 PM   #3 (permalink)
The Contributor
 
webosb's Avatar
 
Join Date: Nov 2007
Posts: 41
Thanks: 24
webosb is on a distinguished road
Default

Sorry for the confusion but this is what I want to accomplish:

- Create a front-end to edit the array values in myData.php

so far, i got the data to display in the front end with this code:

edit.php
PHP Code:
<?php 
require_once('myData.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Editor</title>
<style>
div#container{width: 960px; font: 12px tahoma; line-height: 20px; }
div#container label{ clear: both; display: block; float: left; width: 80px; text-align: right; margin-right: 10px;  }
div#container input{ float: left; width: 500px; }
div#container p.spacer{ display: block; height: 20px; clear: both; }
</style>
</head>

<body>
<div id="container">
<h3>Editor</h3>
<form id="form2" name="form2" method="post" action="">
<?php
$step 
1;
if(
$limitdata) {$i 0;}
foreach (
$data as $datas) {
    if(
$limitdata) { if($i>=$limitdata) continue; }

    
$dataslink $datas['theURL'];
    
$datastitle $datas['title'];
    
$datassometext $datas['someText'];
    
$datasmoretext preg_replace("/<img.+?>/"""$datas['moreText']);
    
$datasthumb $dataimagefolder.$datas['thumbnail'];
    
    
$datacontent "\n";
    
$datacontent .= "<label>Link ".$step."</label><input type=\"text\" name=\"link".$step."\" value=\"".$dataslink."\" />\n";
    
$datacontent .= "<label>Title ".$step."</label><input type=\"text\" name=\"title1\" value=\"".$datastitle."\" />";
    
$datacontent .= "<label>Some Text ".$step."</label><input type=\"text\" name=\"subtitle1\" value=\"".$datassometext."\" />";
    
$datacontent .= "<label>More Text ".$step."</label><input type=\"text\" name=\"teaser1\" value=\"".$datasmoretext."\" />";
    
$datacontent .= "<label>Thumbnail ".$step."</label><input type=\"text\" name=\"image1\" value=\"".$datasthumb."\" />";
    
$datacontent .= "<p class=\"spacer\"></p>  ";

    echo 
$datacontent;
    if(
$limitdata) {$i++;}
    
$step++;
}

?>

</form>
<p>&nbsp;</p>
</div>
</body>
</html>
myData.php
PHP Code:
<?php
$data 
= array(
                array(
                    
"theURL" => "http://www.google.com",
                    
"title" => "Google",
                    
"someText" => "Google Search Engine",
                    
"moreText" => "Google Search Engine. Find whatever you want on the web.",
                    
"thumbnail" => "tn_google.jpg"
                
),

                array(
                    
"theURL" => "http://www.yahoo.com",
                    
"title" => "Yahoo",
                    
"someText" => "Yahoo Search Engine",
                    
"moreText" => "Yahoo Search Engine. Find whatever you want on the web.",
                    
"thumbnail" => "tn_yahoo.jpg"
                
),

                array(
                    
"theURL" => "http://www.msn.com",
                    
"title" => "MSN",
                    
"someText" => "MSN Search Engine",
                    
"moreText" => "MSN Search Engine. Find whatever you want on the web.",
                    
"thumbnail" => "tn_msn.jpg"
                
),                
);
?>

I know I can just create another file to save the POST values and overwrite the myData.php file but I just want to know if there was a better way of doing this (without involving a database).
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
webosb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
Trying to upload files with PHP and Prototype AJAX EyeDentify General 6 01-19-2009 10:04 PM
Opening Php files displays script in browser j4v1 Absolute Beginners 8 06-04-2008 04:23 PM
PHP and external files /\/\ongoose General 16 12-10-2007 05:53 AM
Uploading Files with PHP daz Absolute Beginners 3 09-30-2007 06:23 PM


All times are GMT. The time now is 09:13 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design