dougu5886 2016-02-01 15:25
浏览 95
已采纳

PHP回显$ this-> item->链接在一个href不工作 - 显示JObject->链接

quick question as I'm pulling my hear out!

In a PHP file I have different items pulled through such as contact details etc. I have pulled through $this->item->link which shows a URL which is perfect. I just want to make the url clickable, so I had the following code:

echo "<a href='$this->item->contactlink' target='new'>";
echo $this->item->contactlink;
echo '</a>';

This link doesn't work, stays within the site with a 404 and the URL looks like: http://domain.co.uk/JObject->contactlink

What can I do or have I missed to get the link clickable?

Kind regards Liam

  • 写回答

2条回答 默认 最新

  • dongsanhu4784 2016-02-01 15:33
    关注

    Try:

     <a href="<?php echo $this->item->contactlink; ?>" target='_blank'>
        <?php echo $this->item->contactlink; ?>
     </a> 
    

    Or shorter version:

     <a href="<?= $this->item->contactlink; ?>" target='_blank'>
        <?= $this->item->contactlink; ?>
     </a> 
    

    Target='new' may be part of the issue - I believe target=_blank is standard. Not 100% on the issue, without seeing how you are building '$this'. Also pulling the php elements away from the html helps clear the link reference. Maybe there is an extra quotation for the link?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度