Jump to content

[SOLVED] Echo in a color


Grodo

Recommended Posts

I cant figure out how to echo in a color.

 

Here is my code

 

echo "<font color='#ff1200'>State / Territory Field Missing<br></font>";

 

the error that i receive is

Parse error: parse error, unexpected T_IF in /home/galaxyto/public_html/phpharvest.php

 

I remove the font tag and the script works fine.

 

Thank You

Grodo

Link to comment
https://forums.phpfreaks.com/topic/62485-solved-echo-in-a-color/
Share on other sites

I removed the color tags and it works like a charm how ever only in black text. When I tried it with style I received a different error.

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/galaxyto/public_html/phpharvest.php on line 197

197 is the line with the font tags. I tried

<style font-color:"red">Error Text</style>

<style font-color:"red";>Error Text

 

Is there another way to print out text in PHP?  I Know my code is messy sorry about that :-/

 

 

// Ok lets validate some parameters! With error reporting!
//First we make an array to hold the error code information
$errorcodes = array('ok', 'ok', 'ok', 'ok', 'ok', 'ok');
if ($db_name == "") {
	$errorcodes[0] = ename;
}
if ($db_snumber == "") {
	$errorcodes[1] = esnumber;
}
if ($db_city == "") {
	$errorcodes[2] = ecity;
}
if ($db_state == "") {
	$errorcodes[3] = estate;
}
if ($db_zip == "") {
	$errorcodes[4] = ezip;
}
if ($db_country == "") {
	$errorcodes[5] = ecountry;
}

// Code that gives the ok to process
for ( $i = 0; $i<6; $i++ ) {
	if ( $errorcodes[$i] == "ok" ) {
		$process == TRUE;
	} else {
		$process == FALSE;
	}
}	

if (isset($db_name) && isset($db_snumber) && isset($db_city) && isset($db_state) && isset($db_zip) && isset($db_country) && $process == TRUE)
{
	// Write values to data files code if i posted it would be to long (the code works)
}
 else {
 // Lovely Error Codes :-)
	if ( $errorcodes[0] == "ename")
		echo "<style font-color:"red">State / Territory Field Missing<br></style>";
	if ( $errorcodes[1] == "esnumber")
		echo "Street Number Missing<br>";
	if ( $errorcodes[2] == "ecity")
		echo "City Field Missing<br>";
	if ( $errorcodes[3] == "estate")
		echo "State Field Missing<br>";
	if ( $errorcodes[4] == "ezip" )
		echo "Postal Code Field Missing<br>";
	if ( $errorcodes[5] == "ecountry")
		echo "Country Field Missing<br>";
	}

Change

			echo "<style font-color:"red">State / Territory Field Missing<br></style>";

to

			echo "<style font-color:'red'>State / Territory Field Missing<br></style>";

OR

			echo "<style font-color:\"red\">State / Territory Field Missing<br></style>";

OR

			echo '<style font-color:"red">State / Territory Field Missing<br></style>';

if ( $errorcodes[0] == "ename")
		echo "<style font-color:"red">State / Territory Field Missing<br></style>";

///you are missing your curly brackets around each if statement



	if ( $errorcodes[1] == "esnumber")
		echo "Street Number Missing<br>";

///should be like below
	if ( $errorcodes[2] == "ecity")
		{echo "City Field Missing<br>";}
	if ( $errorcodes[3] == "estate")
		echo "State Field Missing<br>";
	if ( $errorcodes[0] == "ezip" )
		echo "Postal Code Field Missing<br>";
	if ( $errorcodes[0] == "ecountry")
		echo "Country Field Missing<br>";
	}


Report to moderator    Logged  




<style> isn't a tag unless it's used in the head.

 

trying using

 

<p style="color: red;">Text</p>

 

Inline styles are the greatest way of doing things, but they can get the job done.

 

You could also just assign a class in php of red;

 

.red{

    color: red;

}

 

then use <p class="red">

if you are starting your echo statement with double quotes you must escape any double quotes within your string. The same applies to single quotes too.

 

So to echo out this:

<p style="color: red;">Text</p>

 

you'd use

echo "<p style=\"color: red;\">Text</p>";

// OR //

echo '<p style="color: red;">Text</p>';

 

Please re-read Daniel0 echo examples in this post

I figured it out! I just used the print method instead of echo

 

Daniel0 was right echo command does not understand html.

 

this is my new code

print "<font color ='red'>State / Territory Field Missing<br></font>";

 

Thanx to every one who helped!  I will donate to this great resource!

 

Grodo

It didnt have anything to do with the function you used to print the html.

 

 

When you use: "

Any Following "s must be escaped,(  Escape is \  ||| So to escape " you would type \"  ) until the closing ";

 

If you dont want to escape every ", you can also use a single quote '

$variable = "this is my 'example' see?";  // this works ..

 

It also works the other way: $variable = 'blah blah "example" ya';

 

nothing to do with print or echo.. :)

This is my first time coding in php :-x I just kind of jumped into it I have 2 years of Java coding exp so it wasnt so bad. Thanks for all your help guys. LOL im just goign to drop this before a flame war breaks out over PHP echo vs print lol  It be like the Nintendo Ds vs PSP fan boys; only change would be echo method vs print hahahaha! I like this community so lets keep the hatred out :-)

Archived

This topic is now archived and is closed to further replies.

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