前面的話
PHP是一種創建動態交互性站點的強有力的伺服器端腳本語言。 PHP能夠包含文字、HTML、CSS以及PHP程式碼,在伺服器上執行,結果以純文字回傳瀏覽器
程式碼標識
PHP程式碼以結尾,且可以放置在文件中的任何位置
<?<span>php </span><span>// </span>?>
PHP語句以分號(;)結尾,PHP程式碼區塊的關閉標籤也會自動表示分號
<?<span>php echo </span><span>"</span><span>Hello World!</span><span>"</span><span>; </span>?>
註解
『單行註解與一種多行註解<?<span>php </span><span>//</span><span> 这是单行注释</span><span>#这也是单行注释 </span><span>/*</span><span>这是多行注释块 它横跨多行 </span><span>*/</span>?>
[注意]echo和print都是語言結構,有無括號都可以使用echo或echo(),以及print或print() ,且echo或print關鍵字與字串之間至少要有一個空格
<?<span>php
echo </span><span>"</span><span><h2>PHP is fun!</h2>
";
echo "I'm about to learn PHP!
";
echo "This", " string", " was", " made", " with multiple parameters.";
?>
<?<span>php print </span><span>"</span><span><h2>PHP is fun!</h2><span>"</span><span>; print </span><span>"</span><span>Hello world!<br></span><span>"</span><span>; print </span><span>"</span><span>I'm about to learn PHP!<br></span><span>"</span><span>; </span><span>//</span><span>该行出错,因为print只能输出1个字符串</span> print <span>"</span><span>This</span><span>"</span>, <span>"</span><span> string</span><span>"</span>, <span>"</span><span> was</span><span>"</span>, <span>"</span><span> made</span><span>"</span>, <span>"</span><span> with multiple parameters.</span><span>"</span><span>; </span>?>
計算表達式
〜『不同於HTML和寫式
<?<span>php </span><span>//</span><span>36</span> echo <span>12</span>*<span>3</span><span>; </span>?>
大小寫
在PHP中,所有使用者定義的函數、類別和關鍵字都對大小寫不敏感,但所有變數都對大小寫敏感<?<span>php </span><span>//</span><span>Hello World!</span> ECHO <span>"</span><span>Hello World!<br></span><span>"</span><span>; </span><span>//</span><span>Hello World!</span> echo <span>"</span><span>Hello World!<br></span><span>"</span><span>; </span><span>//</span><span>Hello World!</span> EcHo <span>"</span><span>Hello World!<br></span><span>"</span><span>; </span>?>
<?<span>php $color</span>=<span>"</span><span>red</span><span>"</span><span>; </span><span>//</span><span>My car is red</span> echo <span>"</span><span>My car is </span><span>"</span> . $color . <span>"</span><span><br></span><span>"</span><span>; </span><span>//</span><span>My house is </span> echo <span>"</span><span>My house is </span><span>"</span> . $COLOR . <span>"</span><span><br></span><span>"</span><span>; </span><span>//</span><span>My boat is</span> echo <span>"</span><span>My boat is </span><span>"</span> . $coLOR . <span>"</span><span><br></span><span>"</span><span>; </span>?>
以上就介紹了前端學PHP之基礎語法,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。