为什么写在php中依赖于用html编写的img src?

问题描述 投票:-1回答:1

当我拿出<?php ?>下面的HTML代码时,网页不再加载。为什么以下依赖于该代码?我对这个问题的特殊性感到抱歉,但这真让我感到沮丧,我似乎无法独立找到答案。

<?php

    /*Write a function to return an HTML <img /> tag. The function should accept a
    mandatory argument of the image URL and optional arguments for alt text,
    height , and width 
    */
    function html_img ($img_url = "\"https://img.purch.com/h/1400/aHR0cDovL3d3dy5saXZlc2NpZW5jZS5jb20vaW1hZ2VzL2kvMDAwLzA5OS8zMjkvb3JpZ2luYWwvY2hpbXBzLWVhdC1tb25rZXktYnJhaW5zLTAx\"", $alt_text = "\"ronald\"", $height = 400, $width = 1200){


$the_format = "<img src=" . $img_url . "alt=" . $alt_text . " height" . $height . " width=" . $width;

return $the_format;

    }

print html_img();

?>


<!--When the code below is removed, the image is not displayed.-->

<!-- <img src="https://img.purch.com/h/1400/aHR0cDovL3d3dy5saXZlc2NpZW5jZS5jb20vaW1hZ2VzL2kvMDAwLzA5OS8zMjkvb3JpZ2luYWwvY2hpbXBzLWVhdC1tb25rZXktYnJhaW5zLTAx" -->
php html
1个回答
0
投票

$the_format中的图像标签是未闭合的,因此它可能出现在标记中(查看页面源)但如果没有关闭>/>,它将不会以HTML格式呈现

© www.soinside.com 2019 - 2024. All rights reserved.