mpsn Posted November 17, 2011 Share Posted November 17, 2011 Hi, how do I extract a substring? I just want to store "car" in a variable for other uses: Here is the original string: car/red/blue/gun/hit Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/251295-how-to-extract-a-substring/ Share on other sites More sharing options...
DWilliams Posted November 17, 2011 Share Posted November 17, 2011 In that specific example you could do $car = substr('car/red/blue/gun/hit', 0, 3); http://php.net/manual/en/function.substr.php Quote Link to comment https://forums.phpfreaks.com/topic/251295-how-to-extract-a-substring/#findComment-1288856 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2011 Share Posted November 17, 2011 Not enough information. Quote Link to comment https://forums.phpfreaks.com/topic/251295-how-to-extract-a-substring/#findComment-1288857 Share on other sites More sharing options...
mpsn Posted November 17, 2011 Author Share Posted November 17, 2011 I figured it out, if I have: $originalString=car/red/blue/gun/hit then just use: $originalStringToArray=explode("/",$originalString); $firstItem=$originalStringToArray[0] Done! Quote Link to comment https://forums.phpfreaks.com/topic/251295-how-to-extract-a-substring/#findComment-1288859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.