PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old June 12th, 2002, 02:43 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
replacing one item in an array

I need help editting one line in an file acting as an array. I have a file that is a few arrays of links, looks a little like this

$webarray[]="http://www.php.net";
$webarray[]="http://www.cooltext.com";
$generalarray[]="http://amazon.com";
$miscarray[]="http://poo.net";
$webarray[]="http://www.htmlgoodies.com";

I want to edit the file via a web interface, but I can't find a way to read the file, make it editable through some logical interface, and then return just portion I want to edit to the correct spot (or even the entire file with my changes incorporated.) I've tried fwrite...but can't get the formula down. L'il help anyone?

Here's what I'm working with so far...it's dirty and I'd prefer to just scrap it...

php Code:
Original - php Code
  1.  
  2. if($action == "list") {
  3.     $data = file('../../includes/links.inc.php');
  4.    $linenum == "0";
  5.  foreach ($data as $eachlink) {
  6. if ($linenum < 7) {
  7. echo "<font face=tahoma size=2>There is header information on this line<br />n";
  8. $linenum++; }
  9. else {
  10. echo "<FORM ACTION="$PHP_SELF?action=edit&id=$linenum" METHOD="POST" NAME="editform">n";
  11. $element = explode("[]="", $eachlink);
  12. echo $linenum;
  13. echo "&nbsp;&nbsp; current array: <select name=link_array><OPTION SELECTED value="";
  14. $clean = str_replace("$","",$element[0]);
  15. echo "$clean">$clean</option>";
  16. echo "<OPTION name=link_array value=music>music</option>n";
  17. echo "<OPTION name=link_array value=web>web</option>n";
  18. echo "<OPTION name=link_array value=general>general</option>n";
  19. echo "<OPTION name=link_array value=tech>tech</option>n";
  20. echo "</select>";
  21. echo "<input type=text name=link_value value="$element[1]" size=50>&nbsp;";
  22. echo "<INPUT TYPE="submit" NAME="submit" VALUE="Edit This Link"><BR>n";
  23. echo "</form><br />n";
  24. $linenum++; 


I know this is a mess...anyone know how I edit just one item in the array?

Adam

Reply With Quote
  #2  
Old June 12th, 2002, 03:39 AM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: replacing one item in an array

hmmm...wonder why it posted as anonymous? I wonder if it's a Mozilla/cookie bug. IE is getting to be crap, and Mozilla sure is getting slick!

Adam

Reply With Quote
  #3  
Old June 12th, 2002, 10:58 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: replacing one item in an array

Couldn't you use a serialized array, write it into a flat file, and when you call it up somewhere to use it simply unserialize() it?

Reply With Quote
  #4  
Old June 13th, 2002, 01:48 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: replacing one item in an array

I've looked all over, but I don't know how to use serialize() to do this. I thought serialize was mostly for storing array data in MySQL tables. This array is in a text file, and I need to modify just one item.

Reply With Quote
  #5  
Old June 13th, 2002, 02:03 PM
greggory greggory is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Reims, France
Posts: 82 greggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: replacing one item in an array

I think there's a tutorial about sthg like what you want to do:
http://codewalkers.com/tutorials.php

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > replacing one item in an array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek