2014-10-10 22 views
0

我需要獲得此輸出。如何使用php函數在報價中打印字符變量

the result is"random"safdsaf 

我使用這段代碼

<?php 

$x = "random"; 
echo 'the result is' .$x. 'safdsaf'; 
?> 

但我得到這個

the result israndomsafdsaf 

我在打印之前定義隨機的。

即我不想改變這段代碼

<?php 

$x = "random"; 

我應該做哪些改變內部回聲以獲得所需的輸出?

+0

你想看到它後打印報價? – 2014-10-10 07:00:33

回答

1

如果您使用的是同一類型的報價分隔字符串中的引號是這樣的:

echo "The result is\"" .$x. "\"safdsaf"; 

或者乾脆使用兩套不同的報價:

echo 'the result is"' .$x. '"safdsaf'; 

任一條線的輸出代碼:

The result is"random"safdsaf 
0

試試這個

添加了一點空間befor「並補充」,它會給一些列放,只要你想

echo 'the result is "' .$x. '" safdsaf'; 

結果將是

The result is "random" safdsaf 
0

如果你想打印出雙引號你可以將它們包括在單引號中 這樣的事情可以做到這一點。

$x = '"random"'; 

如果出於某種原因你不想使用單引號也可以逃脫他們喜歡:

$x = "\"random\""; 

當你想保持字符串,我建議你改變原來的線路,其中你把它放在:

echo 'the result is"' .$x. '"safdsaf'; 

原則保持不變 下面是一些閱讀材料:http://php.net/manual/en/language.types.string.php

0

您可以簡單地使用: -

echo 'the result is "' .$x. '" safdsaf'; 

或者您也可以使用。

echo "the result is \" $x\" safdsaf"; 
相關問題