简体   繁体   中英

how can I change this Relative Paths to Absolute Paths?

for following code, I would like to know how can I change to absolutely link?

<a class="inline" href="<?php echo $profile->avater->full;?>" id="avater_profile_img">
    <img src="<?php echo $profile->avater->avater;?>" alt="<?php echo $profile->full_name;?>" class="responsive-img" />

    <?php 
        if((int)abs(((strtotime(date('Y-m-d H:i:s')) - $profile->lastseen))) < 60 && (int)$profile->online == 1) { 
            echo '<div class="useronline" style="top: 10px;left: 10px;"></div>'; 
        }
    ?>

</a>

You can use $_SERVER['SERVER_NAME'] to makes the URL Absolute. I have added :// as well before the $_SERVER['SERVER_NAME'] so it may work as per currently viewing scheme either in http or https .

<a class="inline" href="<?php echo $profile->avater->full;?>" id="avater_profile_img">
    <img src="<?php echo '://' . $_SERVER['SERVER_NAME'] . $profile->avater->avater;?>" alt="<?php echo $profile->full_name;?>" class="responsive-img" />

    <?php 
        if((int)abs(((strtotime(date('Y-m-d H:i:s')) - $profile->lastseen))) < 60 && (int)$profile->online == 1) { 
            echo '<div class="useronline" style="top: 10px;left: 10px;"></div>'; 
        }
    ?>

</a>

EDIT:

Use str_replace to change a.com with b.com in the image.

<a class="inline" href="<?php echo $profile->avater->full;?>" id="avater_profile_img">
    <img src="<?php echo str_replace("a.com", "b.com", $profile->avater->avater); ?>" alt="<?php echo $profile->full_name;?>" class="responsive-img" />

    <?php 
        if((int)abs(((strtotime(date('Y-m-d H:i:s')) - $profile->lastseen))) < 60 && (int)$profile->online == 1) { 
            echo '<div class="useronline" style="top: 10px;left: 10px;"></div>'; 
        }
    ?>

</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM