Reply
Search and Replace, like PERL, but in PHP??
Old 05-04-2004, 11:49 AM Search and Replace, like PERL, but in PHP??
Junior Talker

Posts: 4
Hi,

I've been writing PHP for a few months now. It was fairly easy to pick up after knowing PERL. My question is this:

In PERL, you can design a static web page with variables such as USERNAME.. and then in your PERL script you can open the static web page into an array and do a search and replace for the variable, USERNAME, and replace USERNAME with let's say the input variable $username.. so it would look something like this:

Example:

open(STATIC, "staticwebpage.htm") || die "Unable to open web page";
@STATICARRAY = <STATIC>;
close(STATIC);

foreach $line (@STATICARRAY) {
$line =~ s/USERNAME/$username/g;
}

then, you know, print out array..

anyways.. is there a way of doing this in PHP.. bringing static pages into and array and search and replacing content with input variables? what would be the most effective way of doing this in PHP?

Warm Regards,

Angus Bay
__________________
www.angusbay.com || 1-832-667-7240
Web Hosting and Domain Names with Personalized HTML Support
sales@angusbay.com
Angus Bay is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-04-2004, 04:20 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
PHP and Unicode with UTF-8
Posts: 3,108
Location: Toronto, Ontario
Yep, there are a couple functions that do what you want. One is the simple str_replace() which is nice and speedy, used to do very simple things (ie. no regex), things like "{USERNAME}" etc. If you need the power of regex then preg_replace() is thereto the rescue! The examples there pretty much tell you what you need to know, it's also worth looking at the pattern modifiers.
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Reply     « Reply to Search and Replace, like PERL, but in PHP??
 

Thread Tools

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 Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12378 seconds with 13 queries