2013-05-17 144 views
0

簡單的PHP真的,只是不能得到它出於某種原因...包含在PHP回聲內PHP和HTML

<?php 
$myvalue = 'yes' 
if ($myvalue == 'yes') { 
    echo 'This is some test content, within which is some more php bits 
    <?php echo 'Test'; ?> and an if statement 
    <?php if ($anothervalue = "test") { echo 'Print this'; } else 
    { echo 'Print that' ; } ?> 
    And then some more content 
    <br /> 
    Test 
    ?> 

} else { 
    echo 'The value didnt match'; 
} 
?> 

我需要包括回聲裏面的PHP,我怎麼能做到這一點?

+0

使用串聯。 echo'該值不匹配:'。$ myvalue; – Juck

+0

使用'「文本文本<?php echo'我是php';?>」'或者轉義字符串''文本文本<?php echo'我是php' ?>''。如果你想實際打印php代碼。 Else''text「。$ var。」text「.func()。」text「'。 –

回答

0

你必須連接具有.操作串位:

echo 'This is some test content' . ' chained to other stuff' . someFunction() . 'and some other stuff' . $someVariable . ', right?'; 
0

,你可以嘗試像

echo "<img src='".$url."' />"; 
1

串聯據我所知,你不能。 echo只是用於輸出。

改爲重構。

<?php 
    $myvalue = 'yes' 
    if ($myvalue == 'yes') { 
?> 
This is some test content, within which is some more php bits <?php echo 'Test'; ?> and an if statement 
<?php 
    if ($anothervalue = "test") { 
     echo 'Print this'; 
    } else { 
     echo 'Print that' ; 
    } 
?> 
And then some more content 
<br /> 
Test 
<?php 
} else { 
    echo 'The value didnt match'; 
} 
0

echo 'This is some test content, within which is some more php bits &lt;?php echo \'Test\'; ?&gt; and an if statement &lt;?php if ($anothervalue = "test") { echo \'Print this\'; } else { echo \'Print that\' ; } ?&gt';

變化<>到HTML實體&lt; ABD &gt;

1
<?php 

function dosomething($anothervalue){ 
if ($anothervalue = "test") { 
return 'Print this'; } 
else { return 'Print that' ; } 
} 


$myvalue = 'yes' 
if ($myvalue == 'yes') { 
echo 'This is some test content, within which is some more php bits'.dosomething('anothervalue'); ?> 
And then some more content 


?> 
-2

試試這個,但我建議你去W3Schools的和持續的學習之前上來就基礎。

<?php 
    $myvalue = 'yes'; 
    if ($myvalue == 'yes') { 
    echo 'This is some test content, within which is some more php bits Test and an if statement'; 
    if ($anothervalue = "test") { 
     echo 'Print this'; 
    } 
    else { 
     echo 'Print that'; 
    } 
?> 
And then some more content 
<br /> 
Test 
<?php 
    } 
    else 
    { 
     echo 'The value didnt match'; 
    } 
?> 
1

我會建議你創建一個功能第一:

<?php 

function dosomething($anothervalue){ 
if ($anothervalue = "test") { 
return 'Print this'; } 
else { return 'Print that' ; } 
} 

然後包括在您的聲明中/文;

$myvalue = 'yes' 
    if ($myvalue == 'yes') { 
    echo 'This is some test content, within which is some more php bits'.dosomething('anothervalue'); ?> 
    And then some more content 


    ?> 
0

試試這個

<?php 
    $myvalue = 'yes'; 
    if ($anothervalue == "test") { $test = 'Print this'; } else { $test = 'Print that' ; } 
    if ($myvalue == 'yes') { 
     echo "This is some test content, within which is some more php bits $test 
     <br /> 
     Test"; 
    } 
    else 
    { 
     echo 'The value didnt match'; 
    } 
?> 
+0

不需要連接字符串。如果你使用「而不是」作爲你的字符串標識符,你可以直接在字符串中回顯這個變量...... $ test =「world」; echo「Hello $ test」; – zgr024