PHP - get certain word from string

后端 未结 4 1090
陌清茗
陌清茗 2021-01-15 04:47

If i have a string like this:

$myString = \"input/name/something\";

How can i get the name to be echoed? Every string look

相关标签:
4条回答
  • 2021-01-15 05:29

    If you only need "name"

    list(, $name, ) = explode('/', $myString);
    echo "name is '$name'";
    

    If you want all, then

    list($input, $name, $something) = explode('/', $myString);
    
    0 讨论(0)
  • 2021-01-15 05:38

    use the function explode('/') to get an array of array('input', 'name', 'something'). I'm not sure if you mean you have to detect which element is the one you want, but if it's just the second of three, then use that.

    0 讨论(0)
  • 2021-01-15 05:40

    so the only thing you know is that :

    • it starts after input
    • it separated with forward slashes.

    >

    $strArray = explode('/',$myString);
    $name = $strArray[1];
    $something = $strArray[2];
    
    0 讨论(0)
  • 2021-01-15 05:40

    Try this:

    $parts = explode('/', $myString);
    echo $parts[1];
    

    This will split your string at the slashes and return an array of the parts. Part 1 is the name.

    0 讨论(0)
提交回复
热议问题