Doug
Doug

Reputation: 9

Split/Explode in String identifying only the first element (Symbol or Word)?

I have the the next string:

String = "Name: James, Training, Physician, Hobbies: Sports, Reading, Age: 24".

With the following string to share with just the first ':' found, making the following:

stringsplit1 = "Name";
stringsplit2 = "James, Training, Physician, Hobbies: Sports, Reading, Age: 24";

or in the array. : S

Upvotes: 0

Views: 75

Answers (1)

Manwal
Manwal

Reputation: 23816

explode()

explode(':',$string,2);
                    ^ ------------> limit [int]

Complete code:

$string = "Name: James, Training, Physician, Hobbies: Sports, Reading, Age: 24";
$ar = explode(":",$string,2);
print_r($ar);

Upvotes: 1

Related Questions