saf Posted February 8, 2007 Share Posted February 8, 2007 I have a string such as this "something anotherting athirdthing sunrise 7:30 morestuff sunset 6:15 a bunch of other stuff" and I want to pull out specific information in array format (e.g. $Array[sunrise]=>7:30 , $Array[sunset]=>6:15). One of the problems that I am having is that the time changes from day to day. Can anyone give me a function or someting that can solve that? Quote Link to comment Share on other sites More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 Can we see an actual example of the string? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 8, 2007 Share Posted February 8, 2007 You'll probably need to use a regular expression, or just search for the strpos of "sunrise" and then get the substring which is the the next X characters. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 8, 2007 Share Posted February 8, 2007 Well, based upon what you have stated you could probably do something with regular expressions. But, creating a RegEx for that is a little comlpex for me. Instead I would search for the position of "sunrise" and then get the content that starts 8 characters after that till the next space. I'd use the same logic for sunset: $startPos = strpos($text,"sunrise")+8; $endPos = strpos($text," ", $startPos) - $startPos; $Array[sunrise] = substr($text, $startPos, $endPos); $startPos = strpos($text,"sunset")+7; $endPos = strpos($text," ", $startPos) - $startPos; $Array[sunset] = substr($text, $startPos, $endPos); Quote Link to comment Share on other sites More sharing options...
saf Posted February 8, 2007 Author Share Posted February 8, 2007 Well, based upon what you have stated you could probably do something with regular expressions. But, creating a RegEx for that is a little comlpex for me. Instead I would search for the position of "sunrise" and then get the content that starts 8 characters after that till the next space. I'd use the same logic for sunset: $startPos = strpos($text,"sunrise")+8; $endPos = strpos($text," ", $startPos) - $startPos; $Array[sunrise] = substr($text, $startPos, $endPos); $startPos = strpos($text,"sunset")+7; $endPos = strpos($text," ", $startPos) - $startPos; $Array[sunset] = substr($text, $startPos, $endPos); Thanks this worked with slight modifications... Quote Link to comment 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.