Search code examples
phpfile-exists

unexpected value in php using `+` for strings


I´m using this script:

<object data="<?php echo basename(__FILE__, ".php"); ?>.svg"></object>

Now I want to add another line like:

<?php if (file_exists(basename(__FILE__, ".php") + "b.svg")) { ?>
    <object data="<?php echo basename(__FILE__, ".php"); ?>b.svg"></object>
<?php } ?>

This code does not work, the if is never true. I checked the code I'm passing in: basename(__FILE__, ".php") + "b.svg"). The value is page1. But I would expect to get page1b.svg. Why do I get page1 as value ?


Solution

  • Try this:

    <?php if (file_exists(basename(__FILE__, ".php") . "b.svg")) { ?>
    

    replace + with .