douzhuo6931 2016-02-13 08:51
浏览 30
已采纳

连接URL并在URL中显示图像PHP [关闭]

my question is how do you concatenate para1 and para2, and displays the image that is in the url for each of the data in the web1 array in PHP?

Here is an example of what I wanted.

From url1: www.example.com/jferf0923i092eijodsojs

Please keep in mind that these urls are just an example of what I want to achieve.

{"Web 1": {
      "url1": {
        "para1": "www.example.com",
        "para2": /jferf0923i092eijodsojs,
      },
      "url2": { 
        "para1": "www.example.com",
        "para2": asjdoisadj829332oijd,
      },
      "url3": {
        "para1": "www.example.com",
        "para2": assasdijoj21389445,
      }
      }}  

I appreciate your help! Cheers

  • 写回答

1条回答 默认 最新

  • doumu5023 2016-02-13 09:22
    关注

    I assume this is roughly what you are looking for, at least it should give you a start:

    <?php
    $catalog = [
        "Web 1" => [
            "url1" => [
                "para1" => "www.example.com",
                "para2" => "jferf0923i092eijodsojs",
            ],
            "url2" => [
                "para1" => "www.example.com",
                "para2" => "asjdoisadj829332oijd",
            ],
            "url3" => [
                "para1" => "www.example.com",
                "para2" => "assasdijoj21389445",
            ]
        ]
    ];
    
    foreach ($catalog as $entry) {
        foreach ($entry as $url) {
            $imageUrl = sprintf('https://%s/%s', $url['para1'], $url['para2']);
            echo '<img src="' . $imageUrl . '">'."
    ";
        }
    }
    

    The output is valid html and should visualize the image when used inside an html page:

    <img src="https://www.example.com/jferf0923i092eijodsojs">
    <img src="https://www.example.com/asjdoisadj829332oijd">
    <img src="https://www.example.com/assasdijoj21389445">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?