On Mon, 31 Dec 2012 1On Mon, 31 Dec 2012 17:47:00 Stephen D wrote:

> By using require_once instead of fopen and fread, I have simpler code
> and PHP evaluates the embedded variables in $markup without any need to
> use string functions.
> In your case, I would make the file greeter.php
> =====greeter.php===
> $message = "Hello $user_name. How are you today?"
> ===============
> You replace the fopen and fread stuff with a require_once function and
> $message gets included and the user name resolved all in one line of code.
> Hope this helps
> --
> Stephen

Aha! Thanks for the more detailed explanation. I totally misunderstood your
first reply. I understood why I was seeing "$user_name" instead of "Nelson",
but I did not understand what you were trying to tell me.

My greeter file is now:
Hello $user_name.
How are you today?

And my function is simply:
function print_greeting($user_name)
   require_once GREETER_FILE;

Now when I call the function, passing the string "Nelson", it is printing
exactly as I wanted. I used a HEREDOC in the GREETER_FILE because I want to
make it more than that one message, and I want to preserve the line breaks
and formatting when I do.

>From what I've been reading based on other replies, I think templating
will be the way for me to go at some point. I am trying to design a fairly
simple site that will be used internally as a front-end to a simple inventory
database that I've designed. The back-end works fine, but command line result
sets don't appeal to others, so I've embarked on a front-end design. Your
help has gotten me over this step and I can start to expand things. I find
I learn best when I start with some basic functionality and build it up. My
first incarnation was to simply build a static page that output exactly what
I put into it. Once I got that going, I then broke parts off into functions,
and then added parameter passing to the functions. I've already explained
where it went from there to here.

Not to detract from the other replies, but you have lead me to exactly what
I was looking for at the moment. I find smarty (and now a couple of others
picked up from reading about smarty) to be fascinating stuff, but I'm nowhere
near that point yet.

Thanks a million!
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to