Does anyone know how to convert a number such as 1, 2, or 3 to their text version (one, two, three) in PHP? I only need to convert from 1 to 99. I know I could write a huge switch statement but that …
Tag: string
PHP substring extraction. Get the string before the first ‘/’ or the whole string
I am trying to extract a substring. I need some help with doing it in PHP. Here are some sample strings I am working with and the results I need: I want to get the string till the first /, but if no / is present, get the whole string. I tried, I think it says – get the position
Splitting a Paragraph into 160 Character Pieces for Text Messaging
I’m having trouble with the logic of taking a paragraph of text and splitting it on words/sentences to send out in multiple text messages. Each text message can only have up to 160 characters. I want to cleanly break a paragraph up. Here is the solution (thanks Leventix!): Answer You can use wordwrap, then explode by newlines:
How to split a string by multiple delimiters in PHP?
“something here ; and there, oh,that’s all!” I want to split it by ; and , so after processing should get: Answer
Split text using multiple delimiters into an array of trimmed values
I’ve got a group of strings which I need to chunk into an array. The string needs to be split on either /, ,, with, or &. Unfortunately it is possible for a string to contain two of the strings which needs to be split on, so I can’t use split() or explode(). For example, a string could say first
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:
Are php strings immutable?
Or: Should I optimize my string-operations in PHP? I tried to ask PHP’s manual about it, but I didn’t get any hints to anything. Answer PHP already optimises it – variables are assigned using copy-on-write, and objects are passed by reference. In PHP 4 it doesn’t, but nobody should be using PHP 4 for new code anyway.
Convert a String to Variable
I’ve got a multidimensional associative array which includes an elements like I’ve got a strings like: How can I convert the strings into a variable to access the proper array element? This method will need to work across any array at any of the dimensions. Answer Quick and dirty: Of course the input string would need to be be sanitized
PHP equivalent of .NET/Java’s toString()
How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: Like the ToString() method in Java or .NET. Answer You can use the casting operators: There are more details for string casting and conversion in the Strings section of the PHP manual, including special handling for