2013-05-17 93 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