| | |
help with making css/html code be a variable
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2006
Posts: 163
Reputation:
Solved Threads: 2
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.
PHP Syntax (Toggle Plain Text)
$css = "<style type="text/css"> body { background -color: #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)
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
you need to escape the " in the css/html. example:
should be
You could also use the heredoc syntax
there can be NO whitespace in front of CSS;
PHP Syntax (Toggle Plain Text)
$css = "<style type="text/css"> body { background -color: #ffoocc; }";
PHP Syntax (Toggle Plain Text)
$css = "<style type=\"text/css\"> body { background -color: #ffoocc; }";
You could also use the heredoc syntax
PHP Syntax (Toggle Plain Text)
$css =<<<CSS <style type="text/css"> body { background -color: #ffoocc; } CSS;
Last edited by kkeith29; Mar 24th, 2009 at 5:00 pm.
•
•
Join Date: Mar 2006
Posts: 163
Reputation:
Solved Threads: 2
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
html code
PHP code
PHP Syntax (Toggle Plain Text)
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd"> <html xmlns="en" lng="en"> <head> <title> php is cool </title> </head> <body> <?php $pizza = $_POST['pizza']; $taco = $_POST['taco']; $css = '<style type=\"text/css\"> body { background -color: #ffoocc; }";$css = "<style type=\"text/css\"> body { background -color: #ffoocc; }'; if ( $pizza > $taco ) { print '<p> pizza is greater </p>';} else { print '<p> taco is greater </p> $css';} ?> </body> </html>
html code
PHP Syntax (Toggle Plain Text)
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd"> <html xmlns="en" lng="en"> <head> <title> testing </title> </head> <body> <div> <form action= "test3.php" method = "post"> <p> <h1> this form will tell you witch is greater based on what number you put in</h1> enter a number for pizza <input type="text" name="pizza"> enter a number for taco <input type="text" name="taco"> click enter when your satisfied <input type="submit" name="submit" value="submit" /> </form> </div> </body> </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)
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
you can't use variables in string using single quotes. you have to use double quotes.
ex.
should be
or use concatenation (don't know how its spelled)
ex.
PHP Syntax (Toggle Plain Text)
else { print '<p> taco is greater </p> $css';}
PHP Syntax (Toggle Plain Text)
else { print "<p> taco is greater </p> {$css}";}
PHP Syntax (Toggle Plain Text)
else { print '<p> taco is greater </p> '.$css;}
•
•
Join Date: Mar 2006
Posts: 163
Reputation:
Solved Threads: 2
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)
(My interpretation of abstract, is, to change something little by little until it morphs into something new)
try this, i fixed the errors.
PHP Syntax (Toggle Plain Text)
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="en" lng="en"> <head> <title> php is cool </title> </head> <body> <?php $pizza = $_POST['pizza']; $taco = $_POST['taco']; $css = '<style type="text/css"> body { background-color: #ffoocc !important; }'; if ( $pizza > $taco ) { echo '<p> pizza is greater </p>'; } else { echo "<p> taco is greater </p> {$css}"; } ?> </body> </html>
![]() |
Similar Threads
- 'Object variable or With block variable not set' Error (ASP.NET)
- Help transforming mixed complexType (XML, XSLT and XPATH)
- JSP database connectivity according to Model View Controller (MVC) Model 2 (JSP)
- page loading problem (PHP)
- css not working in IE (HTML and CSS)
- Opinions? javascript/php/etc and programming standards (JavaScript / DHTML / AJAX)
- loading a swf file using a variable (ColdFusion)
- I just can't get this Javascript (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: md5 question
- Next Thread: prevent links in textarea
| Thread Tools | Search this Thread |
apache api array basic beginner binary broken cache cakephp checkbox class cms code computing confirm cron curl customizableitems database date delete display dynamic echo email error external file files filter folder form forms forum function functions gc_maxlifetime google headmethod host howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php phpmysql problem query question radio random recursion remote script search select server sessions sms snippet source space sql syntax system table thesishelp trouble tutorial update upload url validator variable video web youtube






