What’s the best way to check if $str1 ends with some string from $arr1? The answer true/false is great, although knowing the number of $arr1 element as an answer (if true) would be great. Example: Is there any better/faster/special way than just comparing in for-statement all elements of $arr1 with the end of $str1? Answer Off the top of my
Tag: string
How to truncate a string in PHP to the sentence closest to a certain number of characters?
I want to truncate/shorten my string to the sentence closest to a ceratain number of characters. I have a working function, but my function truncate to the word closest to a certaion number of …
Convert list into an array using php. How?
I have a function called listelements(), which outputs text like <li>text1</li><li>text2</li>. I have more than 500 elements. Now I want to convert it into an array. Can anyone help me? Thanks. Note: I’m using php Update: The thing i want to achieve is alphabetical navigation. As of now my function displays links in list order. Instead of that i want
Obtain first line of a string in PHP
In PHP 5.3 there is a nice function that seems to do what I want: Unfortunately, the server runs PHP 5.2.17 and the optional third parameter of strstr is not available. Is there a way to achieve this in previous versions in one line? Answer For the relatively short texts, where lines could be delimited by either one (“n”) or
How to assign a variable to one of two strings if one is blank?
I am wondering why this doesn’t work to assign a string to $separator: Elsewhere, $option has been assigned to some text or an empty string. (Actually, in my real life case, it’s some text, or FALSE, but either way…). $separator is TRUE instead of a string. The following accomplishes what I want, but seems unnecessarily verbose: I come from JavaScript,
Remove Same Character once from two different string
I need help in PHP Script. I have two strings. After removing the same character from both string once, Another Two Strings example Output I tried str_replace which replace all the all the characters. Thanks for your helps Answer
PHP: delete the first line of a text and return the rest
What’s the best way to remove the very first line of a text string and then echo the rest in PHP? For example. This is the text string: This is the final output: If I was working with a file in Bash I could do easily the next: sed -i~ 1d target-file Or: tail -n +2 source-file > target-file Any
php: converting number to alphabet and vice versa
So I have this function: function toAlpha($data){ $alphabet = array(‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’); $alpha_flip = …
Split string on non-alphanumeric characters and on positions between digits and non-digits
I’m trying to split a string by non-alphanumeric delimiting characters AND between alternations of digits and non-digits. The end result should be a flat array of consisting of alphabetic strings and numeric strings. I’m working in PHP, and would like to use REGEX. Examples: ES-3810/24MX should become [‘ES’, ‘3810’, ’24’, ‘MX’] CISCO1538M should become [‘CISCO’ , ‘1538’, ‘M’] The input
how to check if PHP variable contains non-numbers?
I just want to know the method to check a PHP variable for any non-numbers and if it also detects spaces between characters? Need to make sure nothing weird gets put into my form fields. Thanks in advance. Answer If you mean that you only want a value to contain digits then you can use ctype_digit().