elmas156 Posted September 8, 2008 Share Posted September 8, 2008 Hey guys, I'm trying to make some things work on my site and I'm having to try some different things. What I'm trying to do is to take a string of text that has been set to a variable and extract certain parts of that string of text to make another variable. For example: <?php $text = "dog/chicken/fish"; //then change this to: $4legs = "dog"; $2legs = "chicken"; $nolegs = "fish"; ?> **Note: This is just an example... I do not really need to make variables to show how many legs a dog, chicken and fish have... only an example to simplify what I'm trying to do ;-) Link to comment https://forums.phpfreaks.com/topic/123264-solved-where-theres-a-will-there-a-way/ Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 Well, it really depends on what you wanna do. In this case <?php $text = "dog/chicken/fish"; list( $legs4, $legs2, $nolegs ) = explode( '/', $text ); echo "$legs4 - $legs2 - $nolegs"; ?> Link to comment https://forums.phpfreaks.com/topic/123264-solved-where-theres-a-will-there-a-way/#findComment-636562 Share on other sites More sharing options...
elmas156 Posted September 8, 2008 Author Share Posted September 8, 2008 Great, it works. What I'm actually trying to do is work with dates and compare them to the current date while sticking with a specific format. Trying to work with date() functions wasn't getting me anywhere so I needed to revert to trying to break down a text string date (09/15/2008) and pull out just the year in order to compare it to current the current date obtained through php ($cyear=date("Y"). What you suggested works great. Thanks discomatt! Link to comment https://forums.phpfreaks.com/topic/123264-solved-where-theres-a-will-there-a-way/#findComment-636585 Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 Glad I could help! Please mark this topic as 'Solved' On another note, if you ever want to turn your date string into a unix timestamp, check out strtotime() and mktime() Link to comment https://forums.phpfreaks.com/topic/123264-solved-where-theres-a-will-there-a-way/#findComment-636635 Share on other sites More sharing options...
elmas156 Posted September 8, 2008 Author Share Posted September 8, 2008 Thanks, I think this is the best solution for now but I'll check into other options as I improve my site. Link to comment https://forums.phpfreaks.com/topic/123264-solved-where-theres-a-will-there-a-way/#findComment-636687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.