Daniel
Daniel

Reputation: 39

Adding php within a php code

Basically what i mean is i want to echo a piece of a php using a php method code below is getting errors

<?php
    $myString = '<?= $_GET['content'] ?>'; 
    echo $myString;
?>

maybe theres a javascript alternative?

full code below

<?php

if (in_array($_GET['content'], array(tree, 3, 4, 5)) ) {
$myString = "<?= $_GET['content'] ?>"; 
$myParsedString = htmlentities($myString); 
echo $myParsedString; 
}
else {

    echo "nothing to see here";

}

?>

Upvotes: 0

Views: 83

Answers (4)

MH2K9
MH2K9

Reputation: 12039

No need to use another PHP tag inside PHP tag. Simply can try this

<?php
if (in_array($_GET['content'], array('tree', 3, 4, 5)) ) {
    $myString = $_GET['content']; 
    $myParsedString = htmlentities($myString); 
    echo $myParsedString; 
}else {
    echo "nothing to see here";
}
?>

Upvotes: 0

Suchit kumar
Suchit kumar

Reputation: 11859

you can directly access $_GET inside <?php ?>no need to use tag again inside :try this.

$myString = $_GET['content']; 

Upvotes: 2

Kiba
Kiba

Reputation: 10827

Just escape the PHP code you get and then u can echo it

$myString = mysql_real_escape_string('<?= $_GET['content'] ?>'); 
echo $myString;

I hope that helps

Upvotes: -1

Rizier123
Rizier123

Reputation: 59681

This should work for you:

if ( in_array($_GET['content'], array("tree", 3, 4, 5)) ) {
    $myString = $_GET['content']; 
    echo $myParsedString = htmlentities($myString); 
} else {
    echo "nothing to see here";
}

Upvotes: 1

Related Questions