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
Share on other sites

there is nothing wrong with the syntax of that line to throw up an error...it must be elsewhere on the script...as for the <font> tags I know nothing about that, I use CSS, so  can't tell you if the html is right or not.  post the rest of the script.

Link to comment
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>";
	}

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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  




Link to comment
Share on other sites

<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">

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.. :)

Link to comment
Share on other sites

You seem like you dont understand alot of the underlying mechanisms of programming .. html and so on. It would do you good to read up a bit on these.. it will help alot in your programming.

 

Buy/checkout some books on HTML, CSS and PHP.

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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