Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 4
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
|| 1-832-667-7240
Web Hosting and Domain Names with Personalized HTML Support

Please login or register to view this content. Registration is FREE
Angus Bay is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-04-2004, 05:20 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Search and Replace, like PERL, but in PHP??
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.40112 seconds with 12 queries