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? Link to comment https://forums.phpfreaks.com/topic/37674-solved-extract-from-string/ 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? Link to comment https://forums.phpfreaks.com/topic/37674-solved-extract-from-string/#findComment-180213 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. Link to comment https://forums.phpfreaks.com/topic/37674-solved-extract-from-string/#findComment-180215 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); Link to comment https://forums.phpfreaks.com/topic/37674-solved-extract-from-string/#findComment-180218 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... Link to comment https://forums.phpfreaks.com/topic/37674-solved-extract-from-string/#findComment-180224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.