String Replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

String Replace

Post by iknownothing »

Hello All,
I was wondering if it were at all possible to replace a certain character throughout an entire include file...

something like this?

Code: Select all

$change = str_replace("hello", "goodbye", include("hellogoodbye.php"));
echo $change;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Unless I'm misunderstanding, yes it's technically possible, but why? I cannot help but wonder if your design isn't optimal if this is required.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

thats what the client wants... I dont really see the point either, but what the client wants, the client gets.

How else would you approach it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Use variables.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Load the file with file_get_contents() and then do the str_replace() on it, then eval() it.

....then find a client that lets you code properly. If they know enough to insist it's done this way I can't help but wonder why they aren't doing it themselves?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

eval() would be worse I suspect. ;)

Okay, I don't suspect that, it's very likely to blow up. :)
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

Kieran Huggins wrote:Load the file with file_get_contents() and then do the str_replace() on it, then eval() it.

....then find a client that lets you code properly. If they know enough to insist it's done this way I can't help but wonder why they aren't doing it themselves?
old grey hair rich people...
Post Reply