How to eval PHP when making a template - getting syntax error
I have an html file where I have a syntax like '@echosomething', then I want to load that html file with file_get_contents and replace the template keyword so that it would echo a variable but I am getting a syntax error.
Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
Here is my html_file.html
<html>
<body>
@echovalue
</body>
And here is my php code
<?php
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = '<?php echo $value; ?>';
$html_file = str_replace('@echovalue', $str, $html_file);
eval($html_file);
echo $html_file;
?>
php templates eval
add a comment |
I have an html file where I have a syntax like '@echosomething', then I want to load that html file with file_get_contents and replace the template keyword so that it would echo a variable but I am getting a syntax error.
Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
Here is my html_file.html
<html>
<body>
@echovalue
</body>
And here is my php code
<?php
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = '<?php echo $value; ?>';
$html_file = str_replace('@echovalue', $str, $html_file);
eval($html_file);
echo $html_file;
?>
php templates eval
1
You're missing a;
on$value = "This is a test value!"
– Nick
Nov 12 '18 at 12:19
getting Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:19
How about escaping special characters?eval(htmlspecialchars($html_file));
– Haris
Nov 12 '18 at 12:24
now I'm getting Parse error: syntax error, unexpected '&', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:24
2
You would be better off (IMHO) looking into a proper template library rather than trying to make something of your own.
– Nigel Ren
Nov 12 '18 at 12:35
add a comment |
I have an html file where I have a syntax like '@echosomething', then I want to load that html file with file_get_contents and replace the template keyword so that it would echo a variable but I am getting a syntax error.
Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
Here is my html_file.html
<html>
<body>
@echovalue
</body>
And here is my php code
<?php
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = '<?php echo $value; ?>';
$html_file = str_replace('@echovalue', $str, $html_file);
eval($html_file);
echo $html_file;
?>
php templates eval
I have an html file where I have a syntax like '@echosomething', then I want to load that html file with file_get_contents and replace the template keyword so that it would echo a variable but I am getting a syntax error.
Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
Here is my html_file.html
<html>
<body>
@echovalue
</body>
And here is my php code
<?php
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = '<?php echo $value; ?>';
$html_file = str_replace('@echovalue', $str, $html_file);
eval($html_file);
echo $html_file;
?>
php templates eval
php templates eval
edited Nov 12 '18 at 12:20
Liga
asked Nov 12 '18 at 12:17
LigaLiga
1219
1219
1
You're missing a;
on$value = "This is a test value!"
– Nick
Nov 12 '18 at 12:19
getting Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:19
How about escaping special characters?eval(htmlspecialchars($html_file));
– Haris
Nov 12 '18 at 12:24
now I'm getting Parse error: syntax error, unexpected '&', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:24
2
You would be better off (IMHO) looking into a proper template library rather than trying to make something of your own.
– Nigel Ren
Nov 12 '18 at 12:35
add a comment |
1
You're missing a;
on$value = "This is a test value!"
– Nick
Nov 12 '18 at 12:19
getting Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:19
How about escaping special characters?eval(htmlspecialchars($html_file));
– Haris
Nov 12 '18 at 12:24
now I'm getting Parse error: syntax error, unexpected '&', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:24
2
You would be better off (IMHO) looking into a proper template library rather than trying to make something of your own.
– Nigel Ren
Nov 12 '18 at 12:35
1
1
You're missing a
;
on $value = "This is a test value!"
– Nick
Nov 12 '18 at 12:19
You're missing a
;
on $value = "This is a test value!"
– Nick
Nov 12 '18 at 12:19
getting Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:19
getting Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:19
How about escaping special characters?
eval(htmlspecialchars($html_file));
– Haris
Nov 12 '18 at 12:24
How about escaping special characters?
eval(htmlspecialchars($html_file));
– Haris
Nov 12 '18 at 12:24
now I'm getting Parse error: syntax error, unexpected '&', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:24
now I'm getting Parse error: syntax error, unexpected '&', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:24
2
2
You would be better off (IMHO) looking into a proper template library rather than trying to make something of your own.
– Nigel Ren
Nov 12 '18 at 12:35
You would be better off (IMHO) looking into a proper template library rather than trying to make something of your own.
– Nigel Ren
Nov 12 '18 at 12:35
add a comment |
2 Answers
2
active
oldest
votes
why not simply
$html_file = str_replace('@echovalue', $value, $html_file);
?
how would you do a foreach loop with this?
– Liga
Nov 12 '18 at 12:27
i'm not sure if i understand your question correctly, what loop do you need?
– Lammi
Nov 12 '18 at 12:49
add a comment |
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = 'return $value;';
echo str_replace('@echovalue', eval($str), $html_file);
echo $html_file;
stilll getting the same erorr..
– Liga
Nov 12 '18 at 12:23
1
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
– Yaroslaw
Nov 12 '18 at 12:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262041%2fhow-to-eval-php-when-making-a-template-getting-syntax-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
why not simply
$html_file = str_replace('@echovalue', $value, $html_file);
?
how would you do a foreach loop with this?
– Liga
Nov 12 '18 at 12:27
i'm not sure if i understand your question correctly, what loop do you need?
– Lammi
Nov 12 '18 at 12:49
add a comment |
why not simply
$html_file = str_replace('@echovalue', $value, $html_file);
?
how would you do a foreach loop with this?
– Liga
Nov 12 '18 at 12:27
i'm not sure if i understand your question correctly, what loop do you need?
– Lammi
Nov 12 '18 at 12:49
add a comment |
why not simply
$html_file = str_replace('@echovalue', $value, $html_file);
?
why not simply
$html_file = str_replace('@echovalue', $value, $html_file);
?
answered Nov 12 '18 at 12:27
LammiLammi
276
276
how would you do a foreach loop with this?
– Liga
Nov 12 '18 at 12:27
i'm not sure if i understand your question correctly, what loop do you need?
– Lammi
Nov 12 '18 at 12:49
add a comment |
how would you do a foreach loop with this?
– Liga
Nov 12 '18 at 12:27
i'm not sure if i understand your question correctly, what loop do you need?
– Lammi
Nov 12 '18 at 12:49
how would you do a foreach loop with this?
– Liga
Nov 12 '18 at 12:27
how would you do a foreach loop with this?
– Liga
Nov 12 '18 at 12:27
i'm not sure if i understand your question correctly, what loop do you need?
– Lammi
Nov 12 '18 at 12:49
i'm not sure if i understand your question correctly, what loop do you need?
– Lammi
Nov 12 '18 at 12:49
add a comment |
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = 'return $value;';
echo str_replace('@echovalue', eval($str), $html_file);
echo $html_file;
stilll getting the same erorr..
– Liga
Nov 12 '18 at 12:23
1
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
– Yaroslaw
Nov 12 '18 at 12:25
add a comment |
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = 'return $value;';
echo str_replace('@echovalue', eval($str), $html_file);
echo $html_file;
stilll getting the same erorr..
– Liga
Nov 12 '18 at 12:23
1
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
– Yaroslaw
Nov 12 '18 at 12:25
add a comment |
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = 'return $value;';
echo str_replace('@echovalue', eval($str), $html_file);
echo $html_file;
$html_file = file_get_contents( 'html_file.html' );
$value = "This is a test value!";
$str = 'return $value;';
echo str_replace('@echovalue', eval($str), $html_file);
echo $html_file;
edited Nov 12 '18 at 12:42
answered Nov 12 '18 at 12:20
YaroslawYaroslaw
834
834
stilll getting the same erorr..
– Liga
Nov 12 '18 at 12:23
1
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
– Yaroslaw
Nov 12 '18 at 12:25
add a comment |
stilll getting the same erorr..
– Liga
Nov 12 '18 at 12:23
1
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
– Yaroslaw
Nov 12 '18 at 12:25
stilll getting the same erorr..
– Liga
Nov 12 '18 at 12:23
stilll getting the same erorr..
– Liga
Nov 12 '18 at 12:23
1
1
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
– Yaroslaw
Nov 12 '18 at 12:25
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
– Yaroslaw
Nov 12 '18 at 12:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262041%2fhow-to-eval-php-when-making-a-template-getting-syntax-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You're missing a
;
on$value = "This is a test value!"
– Nick
Nov 12 '18 at 12:19
getting Parse error: syntax error, unexpected '<', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:19
How about escaping special characters?
eval(htmlspecialchars($html_file));
– Haris
Nov 12 '18 at 12:24
now I'm getting Parse error: syntax error, unexpected '&', expecting end of file in C:xampphtdocstemplatingindex.php(9) : eval()'d code on line 1
– Liga
Nov 12 '18 at 12:24
2
You would be better off (IMHO) looking into a proper template library rather than trying to make something of your own.
– Nigel Ren
Nov 12 '18 at 12:35