-
May 25th, 2012, 08:22 PM
#1
Change font with IF
Hey guys. I was wondering if its possible to change font color based on text.
Im grabbing stock symbols with change
i want it so if the change is negative its red and positive green
how can this be accomplished?
Code:
<body bgcolor="#1C2F2F">
<?php
//Obtain Quote Info
$quote = file_get_contents('http://finance.google.com/finance/info?client=ig&q=NASDAC:' . $stock . '');
//Remove CR's from ouput - make it one line
$json = str_replace("\n", "", $quote);
//Remove //, [ and ] to build qualified string
$data = substr($json, 4, strlen($json) -5);
//decode JSON data
$json_output = json_decode(utf8_decode($data));
// get the last price
$perc = $json_output->cp;
$last = $json_output->l;
$date = $json_output->lt;
$name = $json_output->t;
//Output Stock price .
echo 'Stock Symbol: ' . $name;
echo '<br />';
echo 'Last Price: ' . $last;
echo '<br />';
echo 'Change: ' . $perc;
echo 'Date: ' . $date;
?>
<font color="#0099FF">
<form method="post">
<input type="text" name="myInput" id="myInput">
<input type="submit" name="submit" value="Submit">
</form>
<br /><br />
<font color="#ff0000">
<u>
<?php
echo "$wod1";
?>
<b>:</b></font></u><font color="#fff">
<?php
echo "$wod2";
?></font>
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
May 25th, 2012, 10:34 PM
#2
Re: Change font with IF
Use strpos() to search for the "-". Then change the CSS accordingly.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|