0

Really puzzled on this, probably simple but it is the day after New Years.

I have one line of php 'inline' code that fails to execute on the server before the server sends the page to the browser. Here's the code:

<div>
    <a href="http://localhost/myProj/thePhpFile.php"> Server says this: <?php "DOOSH"; ?> </a>
</div>

That's all I have in the body of my html test page. I'm expecting the inline php to put 'DOOSH' there into the html then send the html over the client. Not happening.

All I see in the browser is "Server says this:" and nothing else.

The reason this has me confused is -- I KNOW the php executes on the server BEFORE the html above is sent over, so why is the DOOSH not being sent? I have tried 'DOOSH', "DOOSH", I even tried writing a php function in the file to return "DOOSH" and nothing works -- do I have a syntax problem here?

(NOTE: Doesn't have much to do with my problem here, but I can successfully click on the "Server says this =>" link and I see thePhpFile.php successfully load, as expected.)

1
  • 1
    You're not telling PHP to do anything with that string. It's simply "there". It's no different than saying <?php $x ?>. If you want the string to be treated as output, you'll have to echo it, exactly as Rich Adams has said in his answer below (which is 100% correct) Commented Jan 2, 2012 at 2:31

3 Answers 3

3

You need to echo it.

<?php echo "DOOSH"; ?>

Or the shorthand way,

<?="DOOSH";?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks -- it worked, even with the function call -- the inline code of <?php echo getTheDooshString(); ?> succeeds, as well as <?php echo "DOOSH" ?>. I'm giving everyone who replied with the 'echo' an 'up-arrow' and I'm accepting this answer -- thanks and Happy New Year.
Keep in mind if you use the short tag <?= ?> , make sure all the servers you are going to use it on support it.
2

I think the syntax you may be looking for is

<?="DOOSH";?>

Right now, you just have a statement which contains the string "DOOSH" but doesn't do anything with it. You either have to use the syntax above or echo it.

<? echo "DOOSH"; ?>

Or maybe I"m totally misunderstanding...

Comments

2
<?php echo "DOOSH"; ?>

Or

<?= "DOOSH"; ?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.