Solved

How can I format my output to certain font size and style?

Posted on 2009-07-07
16
186 Views
Last Modified: 2012-05-07
I currently have simple echo but it looks very rough.  Looking at PHP reference but didn't quite find the method.  Thanks.
echo "<ul>\n";
				  for($i=0; $i<=2; $i++) {
					$event = $eventFeed[$i];
					if($event == nulll)
					   break;
					echo "\t<li>" . $event->title->text .  " (" . $event->id->text . ")\n";
					echo "\t\t<ul>\n";
					foreach ($event->when as $when) {
					  echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
					}
					echo "\t\t</ul>\n";
					echo "\t</li>\n";
				  }
				  echo "</ul>\n";
				?>

Open in new window

0
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +1
16 Comments
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24795925
just echo style attribute, dont ?
0
 
LVL 8

Assisted Solution

by:lharrispv
lharrispv earned 100 total points
ID: 24795947
create some css for the ul.. then when the php echos the css rule should pick it up...
echo "<ul style="color:green; font-weight:bold;">\n";

//the rest of your code
0
 

Author Comment

by:lapucca
ID: 24796079
What about the start time.  I currently have 2009-7-19.  I would like it to display as July 17, 2009.  Also, we have an external css file.  would the code then be like what with the format?  thanks.
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 16

Expert Comment

by:jessc7
ID: 24796090
If you are new to CSS, here is a good starting reference:

http://www.w3schools.com/css/css_intro.asp
0
 
LVL 16

Expert Comment

by:jessc7
ID: 24796137
Here are the various ways to formate a date:

http://us2.php.net/manual/en/function.date.php

So in your case, assuming $when->startTime is in a timestamp format or a date object:
date('F j, Y', $when->startTime);

Open in new window

0
 
LVL 8

Expert Comment

by:lharrispv
ID: 24796157
echo "<ul class="blah">\n";

//the rest of your code

in your external style sheet:

.blah {
..
}
0
 

Author Comment

by:lapucca
ID: 24796445
Why would all my years showing 1969 when it should be 2009?
0
 

Author Comment

by:lapucca
ID: 24796453
Sorry, here is code
					foreach ($event->when as $when) {
					  echo "\t\t\t<li>" . date('F j, Y', $when->startTime).": $event->title </li>\n";
					}			

Open in new window

0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24796530
$when->startTime must be valid timestamp, use mktime http://cz.php.net/manual/en/function.mktime.php for creating valid timestamp
0
 

Author Comment

by:lapucca
ID: 24796605
$when->startTime will return something like 2009-7-19.  How can I change this to July 19, 2009?  I don't see how mktime can do this unless I parse the time first which doesn't sound good.
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24796692
ok here is solution for you - TESTED AND WORKING
$testDate = '2009-7-19';
$testDate2 = split('-', $testDate);
$year = $testDate2[0];
$month = $testDate2[1];
$day = $testDate2[2];
$timestamp = mktime(0,0,0,$month,$day,$year);
$newDate = date('F j, Y', $timestamp);

Open in new window

0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24796704
and it will convert 2009-7-19 to July 19, 2009
0
 
LVL 3

Accepted Solution

by:
Michal-Drozd earned 400 total points
ID: 24797049
so final code will look like:
foreach ($event->when as $when) {
  $testDate = $when->startTime;
  $testDate2 = split('-', $testDate);
  $year = $testDate2[0];
  $month = $testDate2[1];
  $day = $testDate2[2];
  $timestamp = mktime(0,0,0,$month,$day,$year);
  $newDate = date('F j, Y', $timestamp);
  echo "\t\t\t<li>" . newDate .": $event->title </li>\n";
}    

Open in new window

0
 

Author Comment

by:lapucca
ID: 24797112
I modified the follow as attached and my page stops displaying.  I dnot' see what's the causing this though.
					foreach ($event->when as $when) {
						$testDate = $when->startTime;
						$testDate2 = split('-', $testDate);
						$year = $testDate2[0];
						$month = $testDate2[1];
						$day = $testDate2[2];
						$timestamp = mktime(0,0,0,$month,$day,$year);
						$newDate = date('F j, Y', $timestamp);					
						echo "<h1> $newDate: $event->title </h1>\n";
						//echo "<h1>".date('F j, Y', $timestamp).": $event->title </h1>\n";
					}					   
					

Open in new window

0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24797214
add following line at begin. (for showing errors, not blank page):

error_reporting(E_ALL);

note: $when->startTime must be in valid format like 2009-7-19, otherwise line

$testDate2 = split('-', $testDate);

return null and cause error later.
0
 

Author Closing Comment

by:lapucca
ID: 31600681
Miachel,, there were a couple typo in your 2nd sample code but I have finally found them and fixed it.  thank you and everyone else.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question