PHP - get specific word from string

If I have a line like this:

$myString = "input/name/something";

      

How can I get an echo ? Each line looks like this, except for this name, and something might be different.

+2


source to share


4 answers


so the only thing you know is that:

  • starts after typing
  • it is delimited with a forward slash.


<P β†’
$strArray = explode('/',$myString);
$name = $strArray[1];
$something = $strArray[2];

      

+8


source


If you only need "name"

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

      



If you want everything then

list($input, $name, $something) = explode('/', $myString);

      

+4


source


Try the following:

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

      

This will strip your string with forward slashes and return an array of parts. Part 1 is the name.

+3


source


use a function explode('/')

to get an array array('input', 'name', 'something')

. I'm not sure if you mean you need to determine which element you need, but if it's only the second of three then use that.

0


source







All Articles