sridhar sridhar - 3 years ago 206
PHP Question

Content of a php variable not showing up

I am facing an unexpected issue with the following php code.

$vadd = 'settings/images/logo.jpg';
if (strpos($vadd,"settings") == 0){
$vaddr = '<img src = "'.$vadd.'">';
}
$html = '<div style="text-align:center">'.$vaddr.'</div>';
echo $html;


When I run the code in browser, I see the following in the page's source code:

<div style="text-align:center"><img src = ""/>


Why isn't the value of $vadd not showing up? It must be something silly, but I can't figure it out.

Answer Source

I have tested your code i think you dont have image in your mentioned directory so its not returining any think. i have created directory and added logo.jpg and its working fine

<?php

    $vadd = 'settings/images/logo.jpg';
    if (strpos($vadd,"settings")== 0){
        echo $vadd;
        $vaddr= '<img src = "'.$vadd.'">';
        echo $vaddr;
    } 
    $html = '<div style="text-align:center">'.$vaddr.'</div>';
    echo $html;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download