Skip to content
Advertisement

String Splitting PHP

I am wanting to break down a string in to different parts and because of the nature of the string I cant quite get my head around how I could go about doing this or if its possible.

Below is the string that I am trying to break up:

JavaScript

I would like it like:

JavaScript

I was thinking of dooing something like this:

JavaScript

Then trying to build the array back into strings using the ‘ and a start and end point somehow.

Anybody any ideas of any better ways to approach this one?

Advertisement

Answer

You seem to have 2 problems, but this splits it into two parts anyway.

First is to extract the parameters part from the CALL, this finds the first ( and takes the rest of the string. Then it uses rtrim() to strip off the trailing ) (also spaces in case any are there).

The second part is to split the string into each parameter. As it is now effectively a CSV, I use str_getcsv() to split with a ' as the enclosure to keep the groups together…

JavaScript

gives…

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement