Skip to content
Advertisement

Tag: explode

Explode a string to array with key => value

I have string is: How Can I convert from $string to an array with key => value. Updated: @Mark Baker my php version is 5.4 so I cannot test your code, thanks @Aleatoric I’m use this code, but the array return some space character on key and value: I have use trim() to strips all space, but can you tell

explode an array of delimited strings into two arrays

I have the following array: that I need to split into two arrays using “-” as delimiter: and Is there anything like array_explode that does what I want? or a combination of php array functions? I’d like to do this without going through my own for/each loop, if possible, or at least minimize having to reinvent the wheel when something

Explode string only once on first occurring substring

preg_match() gives one match. preg_match_all() returns all matches. preg_split() returns all splits. How can I split only on the first match? Example: This is what I want: Answer Simply set $limit to 2 for 2 parts of the array. Thanks to @BenJames for mentioning: I tested and it works fine. The limit argument: If specified, then only substrings up to

Advertisement