Asked  7 Months ago    Answers:  5   Viewed   49 times

the output is like below restored in a output.txt file:

array (
  'IMType' => '1',
  'Email' => 'test@gmail.com',
  'SignupName' => 'test11',
  'Password' => '11111',
  'Encrypted' => '',
  'Confirm' => '11111',
  'OldPassword' => '',
  'Name' => 'test',
  'SignupProvinceText' => 'province',
  'SignupCity' => 'cityname',
  'Street' => 'street x.y',
  'SignupIndustry' => 'IT',
  'SignupCompany' => 'jobirn',
  'SignupJt' => 'engineer',
  'CellPhoneNum' => '',
  'linked_in' => '',
)

it's in fact output of var_export(my_variable,true),but how to read it into a variable again?

 Answers

18

like this:

$dumpStr = var_export($var,true);
eval('$somevar = ' . $dumpStr.';');
Wednesday, March 31, 2021
 
diegoiglesias
answered 7 Months ago
69

The manual specifies the backslash as unnecessary, which naturally means that if you still use it that the meaning is equivalent. However, as you have pointed out, the manual says that it is supposedly not allowed, which is false.

However, there is something else troubling with the manual. They advertise this:

// importing a global class
use ArrayObject;

If it is true that import names are not processed relative to the current namespace, then use ArrayObject and use ArrayObject must have the same meaning. What else could use ArrayObject refer to other than the global one? In practice, the engine will import the global one.

Also, with bugs such as this: http://bugs.php.net/bug.php?id=49143

I believe there is confusion over what the standard is supposed to be.

To answer your question: there is no difference. However, if I was the engine developer who was also a believer of the no-leading-slash standard, then I wouldn't need to consider a case where someone wrote use Exception;. I believe this was likely the case.

Wednesday, March 31, 2021
 
mgraph
answered 7 Months ago
81

You could use output buffering :

ob_start();

function test ($var) {
    echo $var;
}

test("hello");
$content = ob_get_clean();

var_dump($content); // string(5) "hello"

But it's not a clean and fun syntax to use. It may be a good idea to find a better library...

Wednesday, March 31, 2021
 
Asher
answered 7 Months ago
55

PHPExcel uses file_exists() to test the file before opening it. file_exists() requires stat() support, which is available for a limited subset of stream wrappers such as file:// ftp:// and ssh2.sftp but is not available for http://

You'll need to pull the file to the server's local filesystem first.

Tuesday, August 31, 2021
 
oroshnivskyy
answered 2 Months ago
26

Process the lines inside the loop instead of after it. If you really need the file in a variable:

var=$(<file)
Saturday, September 4, 2021
 
Mike
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share