[resolved]Executing Code inside Function parameter

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
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

[resolved]Executing Code inside Function parameter

Post by LanceEh »

Is there an easy way to execute code inside a function parameter?
Do I need something like eval()?

Example:
function ('first param', echo category_title(); ,'next param');

Thanks!
Last edited by LanceEh on Mon Apr 27, 2009 11:42 am, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Executing Code inside Function parameter

Post by jayshields »

What are you trying to achieve? You shouldn't ever need to do that.
User avatar
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

Re: Executing Code inside Function parameter

Post by LanceEh »

well, I should have been more specific.

Inside wordpress, there is a function to call links to previous items, and it takes text as a parameter for the link.

Right now it is,

Code: Select all

posts_nav_link(' - ','Previous Entries','More Entries'
and I wanted to add the single_cat_title() inside there so it would read

"More Blue Widgets Entries"

but all it turns into is

"More single_cat_title(); Entries"

Is there anyway around this, to execute the code inside the parameter string, (or whatever needs to be done)?

By the way, I can set it as a variable, but I still get
"More $cat Entries"

Any ideas?
Thanks a bunch!
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Executing Code inside Function parameter

Post by McInfo »

Maybe:

Code: Select all

posts_nav_link(' - ', 'Previous Entries', 'More ' . single_cat_title() . ' Entries');
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 12:50 pm, edited 1 time in total.
User avatar
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

Re: Executing Code inside Function parameter

Post by LanceEh »

The only problem with that, is wouldn't 'More ' become one parameter, and ' Entries' another?
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: Executing Code inside Function parameter

Post by ben.artiss »

Notice he used a full stop instead of a comma :wink:

Code: Select all

$var = 'have';
echo 'I '.$var.' nothing';
# outputs: I have nothing
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Executing Code inside Function parameter

Post by McInfo »

Function arguments (and parameters) are separated by commas. There are two commas in that function call, so there are three arguments. The period/dot is the concatenation operator. It concatenates (joins) two strings together. I am assuming that the single_cat_title() function returns a string, so there are three strings ('More ', the return value of single_cat_title(), and ' Entries') that are joined together to form one string that is passed as the third argument to the posts_nav_link() function.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 12:50 pm, edited 1 time in total.
User avatar
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

Re: Executing Code inside Function parameter

Post by LanceEh »

Thanks guys, what I did was change the single quotes to double quotes, and now the $name variable registers correctly inside the parameters.

Thanks again.
Post Reply