开发者

Need help in splitting a string in variable and assign it's parts to an array

开发者 https://www.devze.com 2023-04-02 17:17 出处:网络
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 pre

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' =&开发者_StackOverflow中文版gt; 'something',
    '1' => 'test,
    '2' => '1'
);


$array = explode('/', $string);


There is a php function called explode that does exactly what you want. manual here


Just use $array=explode('/',$string). The explode function does the splitting and returns the array that you want.


explode()

<?php
$te="something/test/1";
$ka=explode('/',$te);
print_r($ka);
0

精彩评论

暂无评论...
验证码 换一张
取 消