问题
I'm trying to write meta keywords dynamically with php, so I have such a code , running in WAMP Server localhost/myfile.php :
<meta name="keywords" content="keyword1, keyword2,
<?php
echo $my_array['index_of_keyword3'];
?>
">
well of course it results in this:
<meta name="keywords" content="keyword1, keyword2,<?php echo $my_array['index_of_keyword3']; ?> ">
So what should I do to get
<meta name="keywords" content="keyword1, keyword2,keyword3 ">
?
Thanks !
By the way, I know I could do this with something like
<?php echo "<meta name=\"keywords\" content=\"keyword1, keyword2,$myVariable\">"; ?>
But I would like to simplify my code, by using php only for the variables.
Edit: omg, I solved the problem by seeing that I'm an idiot :)
I have wrote <?php$row=blabla..?>
changing it to <?php $row=blabla..?>
solved the issue.
Thanks for all the answers. I will upvote them all.
回答1:
I think your problem is that you don't parse the file. How do you call this file because PHP doesn't seem to interpret it?
EDIT: In your wamp config try to disable short open tag
回答2:
I assume your page extention is .html and NOT .php
Change somepage.html to somepage.php and it should start working.
回答3:
Try this:
<meta name="keywords" content="<?php echo implode(",", $my_array);?>">
This way you can print all array content separated with commas. Also make sure your file extension is .php to have your code interpreted.
回答4:
Either your file doesn't have a .php
extension or you're trying to open it directly from filesystem. For PHP to work you need a server, for example XAMPP for Windows of LAMP package for Linux.
When you have a server running, there will be a directory called htdocs
in the server's directory. Put your files in there and type http://localhost/YourFilenameHere
in your browser's address bar to access your files.
来源:https://stackoverflow.com/questions/14900370/how-to-add-php-tags-inside-attribute-value