faqts : Computers : Programming : Languages : PHP : kms : Functions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 4 of 5 people (80%) answered Yes

Entry

Why "(file_exists("filename.ext")) ? echo "text1" : echo "text2";" doesn't work ? Works with print...

Feb 3rd, 2001 00:23
Philip Olson, Luc Abélard,


Ideally, this should be done like this :
  <?php
      echo (file_exists('filename.ext')) ? 'text1' : 'text2'; 
  ?>
No reason to use two echos or prints.  Have a look here :
    What is the difference between echo and print             ?    
    -----------------------------------------------------------
    http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
Print is a function, echo is an expression.  Another faqt that deals 
with this question is here :
    Can I use echo inside a ternary expression                ?
    -----------------------------------------------------------
    http://www.faqts.com/knowledge_base/view.phtml/aid/5/fid/41