问题描述
我正在尝试使用PHP和HTML将图像制作成链接.主要思想是从Twitter上获取用户的图像和屏幕名称,然后通过构建URL并在其末尾添加其屏幕名称,使图像成为指向其个人资料的可点击链接.但是我收到一条错误消息:
I'm trying to make an image into a link using PHP and HTML. The main idea is to grab user's images and screen names from Twitter, then make the image into a clickable link to their profile by building the URL and adding their screen name on the end. But I get a error message:
解析错误:语法错误,意外的T_CONSTANT_ENCAPSED_STRING,期望为','或';'在第71行的C:\ wamp \ www \ fyp \ tweeter3.php中.
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\wamp\www\fyp\tweeter3.php on line 71.
这是第71行(它是foreach循环的一部分):
This is line 71 (it's part of a foreach loop):
<?php echo "<a href = ".$url"><img src = ".$userImage." class = ".$class."></a>"; ?>
我无法查明其中存在语法错误.这些是我的变量:
There's a syntax error in there I just can't pinpoint.These are my variables:
$userScreenName = $user -> screen_name;
$userImage = $user -> profile_image_url;
$class = "myImgClass";
$url = "https://twitter.com/".$userScreenName;
您能发现错误吗?
推荐答案
您在$ url和HTML引号后缺少一个点以生成有效代码:
You are missing a dot after $url and the HTML quotes to generate valid code:
<?php echo "<a href = '".$url."'><img src = '".$userImage."' class = '".$class."'></a>"; ?>
没有引号,您将得到:
<a href = the url><img src = user image class = the class></a>
带引号:
<a href = 'the url'><img src = 'user image' class = 'the class'></a>
这篇关于连接HTML和PHP以建立图像链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!