Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
If i have a string like this:
$myString = "input/name/something";
How can i get the name to be echoed? Every string looks like that except that name and something could be different.
so the only thing you know is that :
>
$strArray = explode('/',$myString); $name = $strArray[1]; $something = $strArray[2];
Add a comment
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.
If you only need "name"
list(, $name, ) = explode('/', $myString); echo "name is '$name'";
If you want all, then
list($input, $name, $something) = explode('/', $myString);
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.
explode('/')
array('input', 'name', 'something')
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.