有一个语法问题与引号在PHP和HTML


Have a Syntax issue with quotes in PHP and HTML

我试图将src指向图像文件夹,但难以获得正确的语法。

get_stylesheet_directory()是一个wordpress特定的php函数,它基本上表示指向主题文件夹。

我没有在这个网站的wordpress特定区域发布这个,因为这纯粹是我遇到的语法问题。

if ($twitter) {
   echo "<a href='$twitter' target='_blank'><img src= " get_stylesheet_directory(). '/images'" height='38' width='37' alt='Twitter'>";  
}
有什么想法吗?

试试这个语法

echo  '<a href="'.$twitter.'" target="_blank"><img src="'.get_stylesheet_directory().'/images" height="38" width="37" alt="Twitter">'; 

PHP中的.运算符将字符串连接在一起。

...src= "get_stylesheet_directory()之间需要一个.,在'/images'和下面的" height='38'..."之间需要另一个.,以正确地将所有字符串连接在一起。

可能是</a>缺失以及缺失的连接,试试这个:

if ($twitter) 
{
   echo "<a href='$twitter' target='_blank'><img src='".get_stylesheet_directory()."/images' height='38' width='37' alt='Twitter'></a>";  
}

还要注意,图像源指向文件夹 /images,而不是图像文件。