phpjay Posted July 13, 2011 Share Posted July 13, 2011 hi guys need help this one i have a date and string and i want the output like this sample text coming from db: 2011-07-06 this is sample remarks 2011-08-06 This is second remarks i want a output like this: 2011-07-06 this is sample remarks 2011-08-06 this is second remarks Quote Link to comment https://forums.phpfreaks.com/topic/241873-string-and-date/ Share on other sites More sharing options...
QuickOldCar Posted July 13, 2011 Share Posted July 13, 2011 It's always best to show your current code. Basically you can just echo the results on the same echo line. echo "$date $string <br />"; or echo $date." ". $string."<br />"; or even style it in a divider with css echo "<div class='mystyle'>$date $string</div>"; Is other ways as well. Quote Link to comment https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242116 Share on other sites More sharing options...
phpjay Posted July 13, 2011 Author Share Posted July 13, 2011 this is mycode $data = "|2011-07-04_This is a sample text|2011-07-14_this is a second sample text "; - this text a sample coming from database $explodeTilde = explode('_', $data); foreach($explodeTilde as $k => $v) { $explodePipe = explode('|', $v); foreach($explodePipe as $k2 => $v2) { $date_entered = date("m/d/Y", strtotime($v2)); echo "<br>"; echo $v2 . ''; } } the output is like this work fine but i dont like to put this by user | _ 2011-07-04 This is a sample text 2011-07-14 this is a second sample text help my code to recode again. and also i want a nextline <br>after the string so that the output will become like this: thanks newbie 2011-07-04 This is a sample text 2011-07-14 this is a second sample text Quote Link to comment https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242146 Share on other sites More sharing options...
QuickOldCar Posted July 13, 2011 Share Posted July 13, 2011 I did 2 different examples, removed extra pipe beginning, then exploded the data, then echo by each exploded position is your date saved as that actual date value? if it is you don't need to use the strtotime and date function look at the difference for both examples //example 1 $data = "|2011-07-04_This is a sample text|2011-07-14_this is a second sample text "; $data = ltrim($data,"|"); $explodedata = explode('|', $data); foreach($explodedata as $exdata) { $exdata = explode('_', $exdata); $date_entered = date("Y-m-d", strtotime($exdata[0])); echo $date_entered ." ". $exdata[1]."<br />"; } example 2 $data = "|2011-07-04_This is a sample text|2011-07-14_this is a second sample text "; $data = ltrim($data,"|"); $explodedata = explode('|', $data); foreach($explodedata as $exdata) { $exdata = explode('_', $exdata); echo $exdata[0] ."<br />". $exdata[1]."<br /><br />"; } output for each would be: 2011-07-04 This is a sample text 2011-07-14 this is a second sample text and 2011-07-04 This is a sample text 2011-07-14 this is a second sample text Quote Link to comment https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242319 Share on other sites More sharing options...
QuickOldCar Posted July 13, 2011 Share Posted July 13, 2011 oops, forgot to comment example 2 //example 1 $data = "|2011-07-04_This is a sample text|2011-07-14_this is a second sample text "; $data = ltrim($data,"|"); $explodedata = explode('|', $data); foreach($explodedata as $exdata) { $exdata = explode('_', $exdata); $date_entered = date("Y-m-d", strtotime($exdata[0])); echo $date_entered ." ". $exdata[1]."<br />"; } //example 2 $data = "|2011-07-04_This is a sample text|2011-07-14_this is a second sample text "; $data = ltrim($data,"|"); $explodedata = explode('|', $data); foreach($explodedata as $exdata) { $exdata = explode('_', $exdata); echo $exdata[0] ."<br />". $exdata[1]."<br /><br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242339 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.