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! 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 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. 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! 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
Archived
This topic is now archived and is closed to further replies.