Include inside a variable / array

Hi,

Ok so I am including inside a variable…

[php]

<?php $bob = include "ip.php"; echo $bob; [/php] In this case ip.php just includes a single IP which is stored by a cron job / another php script , which for some reason I initially assumed would go in to the variable. I suddenly and confusingly got a 1 appear after the address, with a little fiddling and diagnosis I believe It's storing the results in an array and presumably 1 Iis the key. Is there any way I can either force $bob to be a plain ol variable or is it best to get the information I want from it as an array? In theory all the scripts involved could become more complex, but to keep things simple I can keep that IP on its own file. (the ip will be a dynamic ip address basically I just want a variable holding that IP so I can use it elsewhere)

You are assigning $bob as the return value of include()

“Handling Returns: include returns FALSE on failure and raises a warning. Successful includes, unless overridden by the included file, return 1”

You wouldn’t assign include() to a variable. Instead in ip.php you would do $bob = ip_address

Sponsor our Newsletter | Privacy Policy | Terms of Service