variable placeholders in a text file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I have created a simple function that prints a personalized greeting by reading
the greeting contents from a file. I pass the user's name to the function,
and the function reads the file contents into a string variable. I am then
using str_replace to replace the word USER in the string with the user's
name that was passed to the function. Then the function correctly prints
the personalized greeting as I wish.

My question is, is there another way to do something similar, such as
embedding a variable name directly into the text file? In other words,
instead of my text file reading:

Hello USER ...

Can I do something like this:

Hello $user_name ...

and then write my function to replace $user_name with the passed
parameter prior to printing?

The reason I ask is because I am going to want to do three substitutions,
and I'd rather not do three str_replace calls if I don't have to. Plus the
latter seems to be a more robust way of making the changes.

Thanks, and apologies if this has been asked before and I missed it. I'm
just not sure how to phrase this for a search engine.

Nelson 		 	   		  

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux