Skip to content
Advertisement

Tag: c#

C# String.Format() Equivalent in PHP?

I’m building a rather large Lucene.NET search expression. Is there a best practices way to do the string replacement in PHP? It doesn’t have to be this way, but I’m hoping for something similar to the C# String.Format method. Here’s what the logic would look like in C#. Is there a PHP5 equivalent? Answer You could use the sprintf function:

Calling a function from a string in C#

I know in php you are able to make a call like: Is this possible in .Net? Answer Yes. You can use reflection. Something like this: With the above code, the method which is invoked must have access modifier public. If calling a non-public method, one needs to use the BindingFlags parameter, e.g. BindingFlags.NonPublic | BindingFlags.Instance:

Advertisement