WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Sed, a coder's best friend. This lovely linux command allows you to swap strings in a file. Great for changing a variable name in a script with multiple files.
Categories : HTML and PHP, HTML and PHP Update Picture
Tim Crider
Date : Jun 21st 1999
Grade : 1 of 5 (graded 1 times)
Viewed : 11370
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Tim Crider
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This is mainly for the Linux / *nix type developers. This will show you a small example of how to change the values of something in multiple files, without having to open each ove of
them up in an editor and doing it by hand.

example:
2 files: a.php3 b.php3

Contents
a.php3:
----
Hello World
----
b.php3:
----
GoodBye World
----

in that same directory type (Each on a new line ):

for i in *.php3 ; do
sed s^World^Planet^g < $i > $i.new
mv $i.new $i
done

Now read the files... they should read Hello Planet and Goodbye Planet

For a break down of those commands:

1 for i in *.php3 ; do
2 sed s^World^Planet^g < $i > $i.new
3 mv $i.new $i
4 done

Line 1:
sets up a loop that will execute the following functions until the construct no longer exists.
i is the counter, and *.php3 signifies that only files that end in .php3 will be effected.
; do actually starts the loop

Line 2:
sed (Stream EDitor), This command takes the target files, and reads them line by line... and changes the lines if they match the pattern.

syntax:
sed s^Target_String^Replacement_String^g < $i > $i.new

sed s = search and replace
Target_String = The string sed looks for
Replacement_String = The string that is put in place of the Target String
g = Globally. This means that if Hello Hello is on one line BOTH will be changed, if no g is added, only the first instance will be changed.
< $i = Takes the contents of the current file ($i) -- (Which is whatever *.php3 file is currently in the loop), and dumps it into set. (ex: x.php3)
> $i.new = Takes the RESULT of the sed command and dumps it into (current_file.new) (ex: x.php3.new)

Line 3:
moves x.php3.new to x.php3 (writes the changes to the old file)

Line 4:
ends the script.

This script has helped me incredibly time and time again, it has saved me hours of coding, by manipulating large groups of files without me ever having to open them up and editing
them. For more information on sed check out man sed on your linux box

Tim



PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Simple Generic Drop Down List Function
Categories : PHP, HTML and PHP, Functions
Class to build a select tag in html, useful to build select boxes from a data base
Categories : PHP, HTML and PHP, PHP Classes
Dynamic generation of textboxes, select items etc in a table for use with databases applications, matrimonials and for job sites
Categories : PHP, HTML and PHP, Java Script
phpAddQuote v1.2 - UPDATED! Lets users add their own quotes to your website. You specify how many quotes appear on the page at a time. Easier install!
Categories : HTML and PHP, Complete Programs, PHP, Databases, Personalization and Membership
phpWebCam v1.0- Webcam management software - Automatically checks if you're online, and comes with a caption tool capable of handling multiple users.
Categories : PHP, Complete Programs, HTML and PHP
Dynamic Page
Categories : Frameworks, PHP, HTML and PHP
Simple PHP/3 Access Counter (using GD and DBM functions)
Categories : Databases, PHP, Graphics, HTML and PHP, dBase
Paginating the mySQL data
Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP
DDN FFA Network Script
Categories : PHP, MySQL, Complete Programs, HTML and PHP, Databases
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
EditPHP - PHP HTML online file editor with encrypted password authentication.
Categories : HTML and PHP, PHP Classes, PHP Options and Info
How to Create a Shoutbox Using PHP & MySQL
Categories : PHP, MySQL, Web Applications, Beginner Guides, HTML and PHP
Popup Menu 0.5, popup, select, html, state-maintaing
Categories : HTML, PHP, HTML and PHP
On-the-fly drop down menu from a txt or xml file
Categories : PHP, XML, HTML and PHP