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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.