PHP 脚本不适用于元描述?推特卡片更新
PHP script not working for meta description? Update for twitter cards
我只是想制作这个随机脚本,使元、开放图表和 Twitter 卡片更容易结合在一起。
这是我的PHP代码
<?PHP
$Title = "This is the Open Grah script";
$Description = "This is the one and only Description, or better yeh the first 150 charecters of the main content on your page. What ever you feel like really!";
echo "<html>
<head>
<title> $Title </title>";
echo '<meta name="description" content=" ';
echo '$Description';
echo '" />';
?>
但这是在浏览器中源代码中发生的情况:
<html>
<head>
<title> This is the Open Grah script </title><meta name="description" content=" $Description" />
所以基本上它不会打印 $Description
变量。
更新
<?PHP
$Title = "This is the Open Grah script";
$Description = "This is the one and only Description, or better yeh the first 150 charecters of the main content on your page. What ever you feel like really!";
$Twitter = "@obama";
echo "<html>
<head>
<title> $Title </title>";
echo '<meta name="description" content=" ';
echo $Description;
echo '" />';
echo "<meta name="twitter:card" content="summary" />";
echo '<meta name="twitter:site" content"';
echo $Twitter
echo '"/>';
echo '<meta name="twitter:title" content"';
echo $Title;
echo '" />';
echo '<meta name="twitter:description" content" ';
echo $Description;
echo '" />';
?>
所以它一开始是有效的,但现在不工作了,没有真正看到错误。
打印一个带有单引号的 php 变量 '$Description' 它假定为字符串而不是变量所以你应该用双引号括起来 "$描述".
改变
echo '$Description';
到
echo "$Description";
或者简单的回显变量
echo $Description;
而不是像这样使用 echo '$Description';
像这样使用 echo $Description;
在 PHP 中的单引号中,美元符号不被解释,双引号,或者什么都不解释:
echo $Description;
或
echo "$Description";
我只是想制作这个随机脚本,使元、开放图表和 Twitter 卡片更容易结合在一起。
这是我的PHP代码
<?PHP
$Title = "This is the Open Grah script";
$Description = "This is the one and only Description, or better yeh the first 150 charecters of the main content on your page. What ever you feel like really!";
echo "<html>
<head>
<title> $Title </title>";
echo '<meta name="description" content=" ';
echo '$Description';
echo '" />';
?>
但这是在浏览器中源代码中发生的情况:
<html>
<head>
<title> This is the Open Grah script </title><meta name="description" content=" $Description" />
所以基本上它不会打印 $Description
变量。
更新
<?PHP
$Title = "This is the Open Grah script";
$Description = "This is the one and only Description, or better yeh the first 150 charecters of the main content on your page. What ever you feel like really!";
$Twitter = "@obama";
echo "<html>
<head>
<title> $Title </title>";
echo '<meta name="description" content=" ';
echo $Description;
echo '" />';
echo "<meta name="twitter:card" content="summary" />";
echo '<meta name="twitter:site" content"';
echo $Twitter
echo '"/>';
echo '<meta name="twitter:title" content"';
echo $Title;
echo '" />';
echo '<meta name="twitter:description" content" ';
echo $Description;
echo '" />';
?>
所以它一开始是有效的,但现在不工作了,没有真正看到错误。
打印一个带有单引号的 php 变量 '$Description' 它假定为字符串而不是变量所以你应该用双引号括起来 "$描述".
改变
echo '$Description';
到
echo "$Description";
或者简单的回显变量
echo $Description;
而不是像这样使用 echo '$Description';
像这样使用 echo $Description;
在 PHP 中的单引号中,美元符号不被解释,双引号,或者什么都不解释:
echo $Description;
或
echo "$Description";