Jump to content

string and date


phpjay

Recommended Posts

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

 

         

 

Link to comment
https://forums.phpfreaks.com/topic/241873-string-and-date/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242116
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242146
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242319
Share on other sites

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 />";

}

Link to comment
https://forums.phpfreaks.com/topic/241873-string-and-date/#findComment-1242339
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.