help with making css/html code be a variable

Thread Solved

Join Date: Mar 2006
Posts: 163
Reputation: grunge man is an unknown quantity at this point 
Solved Threads: 2
grunge man grunge man is offline Offline
Junior Poster

help with making css/html code be a variable

 
0
  #1
Mar 24th, 2009
I tried doing this, and it didnt work. Im goign to identify the $css in the else of an if else statement; so when its else, it willl turn the web page that color, but i cant figure out how to acomplish it.
  1. $css = "<style type="text/css">
  2. body {
  3. background -color: #ffoocc;
  4. }";
THE ONLY WAY TO MOVE IN THE FUTURE IS TO ABSTRACT IN THE PAST
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: help with making css/html code be a variable

 
0
  #2
Mar 24th, 2009
you need to escape the " in the css/html. example:
  1. $css = "<style type="text/css">
  2. body {
  3. background -color: #ffoocc;
  4. }";
should be
  1. $css = "<style type=\"text/css\">
  2. body {
  3. background -color: #ffoocc;
  4. }";

You could also use the heredoc syntax
  1. $css =<<<CSS
  2. <style type="text/css">
  3. body {
  4. background -color: #ffoocc;
  5. }
  6. CSS;
there can be NO whitespace in front of CSS;
Last edited by kkeith29; Mar 24th, 2009 at 5:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 163
Reputation: grunge man is an unknown quantity at this point 
Solved Threads: 2
grunge man grunge man is offline Offline
Junior Poster

Re: help with making css/html code be a variable

 
0
  #3
Mar 24th, 2009
ok cool that worked but it didnt execute that css code it just came up as $css and i tried it with " " and ' ' didnt make a defrence then i tried just putting $css in the else statement didnt work here is my hole coding

PHP code
  1. <DOCTYPE html PUBLIC "-//W3C//DTD XHTML
  2. 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/
  4. xhtml1-transitional.dtd">
  5. <html xmlns="en" lng="en">
  6. <head>
  7.  
  8. <title> php is cool </title>
  9. </head>
  10. <body>
  11.  
  12. <?php
  13.  
  14. $pizza = $_POST['pizza'];
  15. $taco = $_POST['taco'];
  16.  
  17. $css = '<style type=\"text/css\">
  18. body {
  19. background -color: #ffoocc;
  20. }";$css = "<style type=\"text/css\">
  21. body {
  22. background -color: #ffoocc;
  23. }';
  24.  
  25.  
  26.  
  27. if ( $pizza > $taco ) { print '<p> pizza is greater </p>';}
  28. else { print '<p> taco is greater </p> $css';}
  29.  
  30. ?>
  31.  
  32. </body>
  33. </html>

html code
  1. <DOCTYPE html PUBLIC "-//W3C//DTD XHTML
  2. 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/
  4. xhtml1-transitional.dtd">
  5. <html xmlns="en" lng="en">
  6. <head>
  7.  
  8. <title> testing </title>
  9. </head>
  10. <body>
  11. <div>
  12. <form action= "test3.php" method = "post">
  13. <p>
  14. <h1> this form will tell you witch is greater based on what number you put in</h1>
  15. enter a number for pizza <input type="text" name="pizza">
  16. enter a number for taco <input type="text" name="taco">
  17. click enter when your satisfied
  18. <input type="submit" name="submit" value="submit" />
  19.  
  20. </form>
  21. </div>
  22. </body>
  23. </html>
THE ONLY WAY TO MOVE IN THE FUTURE IS TO ABSTRACT IN THE PAST
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: help with making css/html code be a variable

 
0
  #4
Mar 24th, 2009
you can't use variables in string using single quotes. you have to use double quotes.
ex.
  1. else { print '<p> taco is greater </p> $css';}
should be
  1. else { print "<p> taco is greater </p> {$css}";}
or use concatenation (don't know how its spelled)
  1. else { print '<p> taco is greater </p> '.$css;}
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 163
Reputation: grunge man is an unknown quantity at this point 
Solved Threads: 2
grunge man grunge man is offline Offline
Junior Poster

Re: help with making css/html code be a variable

 
0
  #5
Mar 24th, 2009
k still didnt turn the background to #ffoocc
THE ONLY WAY TO MOVE IN THE FUTURE IS TO ABSTRACT IN THE PAST
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: help with making css/html code be a variable

 
0
  #6
Mar 24th, 2009
in the css, there is no space between background and -color
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 163
Reputation: grunge man is an unknown quantity at this point 
Solved Threads: 2
grunge man grunge man is offline Offline
Junior Poster

Re: help with making css/html code be a variable

 
0
  #7
Mar 24th, 2009
tecknikly actually there is a space before and after the "-" i just messed up a bit ll didnt fix it though im preaty shure that santax errors arnt causing the problem
Last edited by grunge man; Mar 24th, 2009 at 5:51 pm.
THE ONLY WAY TO MOVE IN THE FUTURE IS TO ABSTRACT IN THE PAST
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: help with making css/html code be a variable

 
0
  #8
Mar 24th, 2009
try this, i fixed the errors.
  1. <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="en" lng="en">
  3. <head>
  4. <title> php is cool </title>
  5. </head>
  6. <body>
  7. <?php
  8.  
  9. $pizza = $_POST['pizza'];
  10. $taco = $_POST['taco'];
  11.  
  12. $css = '<style type="text/css">
  13. body {
  14. background-color: #ffoocc !important;
  15. }';
  16.  
  17. if ( $pizza > $taco ) {
  18. echo '<p> pizza is greater </p>';
  19. }
  20. else {
  21. echo "<p> taco is greater </p> {$css}";
  22. }
  23.  
  24. ?>
  25. </body>
  26. </html>
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: help with making css/html code be a variable

 
0
  #9
Mar 24th, 2009
where did you learn that there is a space? according to many sites, there isn't suppose to be.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 163
Reputation: grunge man is an unknown quantity at this point 
Solved Threads: 2
grunge man grunge man is offline Offline
Junior Poster

Re: help with making css/html code be a variable

 
0
  #10
Mar 24th, 2009
nope
THE ONLY WAY TO MOVE IN THE FUTURE IS TO ABSTRACT IN THE PAST
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC