Reputation: 1083
One of my variable in my PHP script produce strings like:
'something/test/1'
I want to split that kind of strings through the keyword /
and then assign those parts to an array in PHP by using preg_match
or something else.
The output should look like:
array(
'0' => 'something',
'1' => 'test,
'2' => '1'
);
Upvotes: 0
Views: 339
Reputation: 11863
<?php
$te="something/test/1";
$ka=explode('/',$te);
print_r($ka);
Upvotes: 2
Reputation:
Just use $array=explode('/',$string)
. The explode
function does the splitting and returns the array that you want.
Upvotes: 4
Reputation: 15676
There is a php function called explode
that does exactly what you want. manual here
Upvotes: 4