Maison > Article > développement back-end > php涓殑鍗曞紩鍙枫€佸弻寮曞彿鍜岃浆涔夊瓧绗PHP鏁欑▼ | 甯涔嬪
PHP鍗曞紩鍙峰強鍙屽紩鍙峰潎鍙互淇グ瀛楃涓茬被鍨嬬殑鏁版嵁锛屽鏋滀慨楗扮殑瀛楃涓蹭腑鍚湁鍙橀噺锛堜緥$name锛夛紱鏈€澶х殑鍖哄埆鏄細 鍙屽紩鍙蜂細鏇挎崲鍙橀噺鐨勫€硷紝鑰屽崟寮曞彿浼氭妸瀹冨綋鍋氬瓧绗︿覆杈撳嚭銆?/p>
渚嬪锛?/p>
$name="string";
echo " 瀛楃涓?quot; . '$name';
echo "瀛楃涓?quot; . "$name";
?>
缁撴灉锛?/p>
瀛楃涓?name
瀛楃涓瞫tring
杞箟瀛楃锛岄【鍚嶆€濅箟浼氬皢瑙勫畾鐨勮娉曠敤"\"鏉ヨ緭鍑恒€備絾璇硶瑙勫畾鍦ㄤ笉鍚岀殑绯荤粺涓浆涔夊瓧绗︾殑浣滅敤涓嶅悓锛屼緥濡傦細windows涓嬬殑鍥炶溅鎹㈣绗︾敤"\r"鎴?quot;\n"锛岃€孡inux 杩欎袱灏辨湁寰堝ぇ鐨勫尯鍒細"\r"鍏夋爣鍥炲埌琛岄锛屼絾杩樺湪鏈; "\n"琛ㄧず涓嬩竴琛岋紝涓嶄細鍥炲埌琛岄銆?/p>
PHP涓殑杞箟瀛楃鏈?
" \n" ==>鎹㈣
"\r"==>鍥炶溅
"\t"==>姘村钩鍒惰〃绗?nbsp;
"\\"==> 鍙嶆枩鏉?/p>
"\$" ==>缇庡厓绗﹀彿
" \' "==>鍗曞紩鍙?nbsp;
" \" " ==>鍙屽紩鍙?/p>
" \[0-7]{1,3} " 姝e垯琛ㄨ揪寮忓尮閰嶄竴涓叓杩涘埗绗﹀彿琛ㄧず鐨勫瓧绗?/p>
" \x[0-9A-Fa-f]{1,2} " 姝e垯琛ㄨ揪寮忓尮閰嶄竴涓崄鍏繘鍒剁鍙疯〃绀虹殑瀛楃
鍦≒HP涓紝鍙互浣跨敤 echo() 鍜?print() 璇彞鍙戦€佹暟鎹埌Web娴忚鍣紝涔熷彲浠ヤ娇鐢ㄥ畠浠彂閫丠TML 浠g爜鍒癢eb娴忚鍣ㄣ€備粠鎶€鏈笂璁诧紝echo() 鍜?print() 鏄瑷€鏋勯€狅紝鑰屼笉鏄嚱鏁帮紝杩欓噷鐢ㄤ簡涓€瀵规嫭鍙凤紝浠庤€屾湁鍔╀簬涓庡彉閲忎互鍙奝HP鐨勫叾浠栭儴鍒嗗尯鍒嗗紑銆傝繖涓や釜璇彞鏈川涓婃病鏈変粈涔堝尯鍒紝鍥犳鐢ㄩ偅涓€涓兘涓嶄細浜х敓浠讳綍闂銆傝繖渚濅釜浜轰範鎯€傚畠浠笉鍖哄垎澶у皬瀛椼€?/p>
鍦≒HP涓紝鐞嗚В鍗曞紩鍙蜂笌鍙屽紩鍙锋湁浠€涔堝尯鍒槸閲嶈鐨勩€傚綋鎵€鍙戦€佺殑鏁版嵁涓秹鍙婂埌鍗曞紩鍙峰拰鍙屽紩鍙锋椂锛屽湪鎵撳嵃鍙屽紩鍙锋椂浣跨敤鍗曞紩鍙凤紝鍙嶄箣浜︾劧锛屽锛?/p>
echo 'She said,"How are you?"';
print "I'm just ducky.";
鎴栬€咃紝閫氳繃鍦ㄦ湁闂鐨勫瓧绗﹀墠闈㈡斁缃竴涓弽鏂滄潬锛屽瀹冭繘琛岃浆涔夛細
echo "She said,\"How are you?\" ";
print 'I\'m just ducky.';
鍦≒HP涓紝灏侀棴鍦ㄥ崟寮曞彿鍐呯殑鍊煎皢鐓у瓧闈㈡剰涔夎繘琛屽鐞嗭紝鑰屽皝闂湪鍙屽紩鍙峰唴鐨勫€煎垯灏嗚瑙i噴銆傛崲鍙ヨ瘽璇达紝鎶婂彉閲忓拰鐗规畩瀛楃锛堣琛?锛夋斁鍦ㄥ弻寮曞彿鍐呭皢瀵艰嚧鎵撳嵃鍑哄畠浠墍琛ㄧず鐨勫€硷紝鑰屼笉鏄畠浠殑瀛楅潰鍊笺€傚锛?/p>
$var = 'test';
浠g爜echo "var is equal to $var"; 灏嗘墦鍗板嚭 var is equal to test锛岃€屼唬鐮乪cho 'var is equal to $var'; 灏嗘墦鍗板嚭var is equal to $var銆備娇鐢ㄤ竴涓浆涔夌殑缇庡厓绗﹀彿锛屼唬鐮乪cho"\$var is equal to $var"; 灏嗘墦鍗板嚭$var is equal to test锛岃€屼唬鐮乪cho '\$var is equal to $var'; 灏嗘墦鍗板嚭\$var is equal to $var銆?/p>
琛? 褰撳湪鍙屽紩鍙峰唴浣跨敤杩欎簺瀛楃鏃讹紝瀹冧滑鍏锋湁鐗规畩鐨勫惈涔?/p>
杞箟瀛楃浠g爜 杞箟瀛楃鐨勫惈涔?br /> \ " 鍙屽紩鍙?br /> \ ' 鍗曞紩鍙?br /> \ \ 鍙嶆枩鏉?br /> \ n 鎹㈣绗?br /> \ r 鍥炶溅绗?br /> \ t 鍒惰〃绗?br /> \ $ 缇庡厓绗﹀彿
姝e浠ヤ笂渚嬪瓙鎵€璇存槑鐨勶紝鍙屽紩鍙峰皢鐢ㄥ彉閲忕殑鍊硷紙test锛変唬鏇垮畠鐨勫悕绉帮紙$var锛夛紝骞剁敤鐗规畩瀛楃琛ㄧず鐨勫€硷紙$锛変唬鏇垮畠鐨勪唬鐮侊紙\$锛夈€傚崟寮曞彿鎬绘槸鍑嗙‘鍦版墦鍗颁綘杈撳叆鐨勫唴瀹癸紝闄や簡杞箟鐨勫崟寮曞彿锛圽'锛夊拰杞箟鐨勫弽鏂滄潬锛圽\锛変箣澶栵紝瀹冧滑灏嗗垎鍒鎵撳嵃涓轰竴涓崟寮曞彿鍜屼竴涓弽鏂滄潬銆?/p>
鎻愮ず锛?/p>
1銆佺敱浜嶱HP灏嗚瘯鍥炬壘鍑洪偅浜涢渶瑕佸皢鍏跺€兼彃鍏ュ埌鍙屽紩鍙峰唴鐨勫彉閲忥紝鎵€浠ヤ粠鐞嗚涓婅锛屼娇鐢ㄥ崟寮曞彿瑕佸揩涓€浜涖€備絾鏄紝濡傛灉闇€瑕佹墦鍗颁竴涓彉閲忕殑鍊硷紝鍒欏繀椤讳娇鐢ㄥ弻寮曞彿銆?/p>
2銆佸洜涓烘湁鏁堢殑HTML甯稿父鍖呮嫭璁稿鐢ㄥ弻寮曞彿鎷綇鐨勫睘鎬э紝鎵€浠ュ綋鍒╃敤PHP鎵撳嵃HTML鏃讹紝浣跨敤鍗曞紩鍙锋渶瀹规槗銆?/p>
echo '