通过php在LocalHost上img的绝对路径

Working on a personal project, having some confusion with img src attribs being supplied by in-line php. I also meant to ask, is in-line php generally look upon as poor practice?

Here's the code snip in any case

<li>
<?php  
    $username = $_SESSION["username"];
    echo($username);
?>
</li>

<li><img 
<?php 
$xml = new DomDocument("1.0");

if(file_exists("data/posts/$username/$username.xml")){
    $xml->load("data/posts/$username/$username.xml");
    $postsArray = $xml->getElementsByTagName('post');
}else{
    echo ("Cannot reach image store");
}

foreach($postsArray as $post){
    $profPic = $post->getElementsByTagName("profpic")[0]->nodeValue;

    if($profPic == 'true'){
        $imgPath = $post->getElementsByTagName("path")[0]->nodeValue;

        $imgPath = str_replace("C:","localhost",$imgPath);
        $imgPath = str_replace("\\","/", $imgPath);
        echo ("src=\"http://".$imgPath."\"");
    }
}
?>
>
</li>

The issue I'm having is that the string it pumps out is

 <li>
 <img src="http://localhost/xampp/htdocs/hobnobv2/data/posts/liar/1.jpg"    >
 </li>

but is unable to load the image. The image exists in the directory.

C:\xampp\htdocs\hobnobv2\data\posts\liar

Any guidance you can give to me? I understand that the str_replace's are inefficient and I should probably be saving the "http://localhost/path/to/image.xml" string in my xml file, but is there a reason the image won't load?

Thanks everybody. My heart goes out to you all.

There was an answer here but it's gone now.

The issue was I had the straight up wrong URL.

http://localhost/hobnobv2/data/posts/liar/1.jpg

rather than

http://localhost/xampp/htdocs/data/posts/liar/1.jpg

Thanks to the guy who posted this originally, lost to the sands of time. Hope this helps someone.