2

Can i convert the this text to array type. Because I curl for get result on somepage but it's return to text not array.

$array="Array ( [Dog] => Array ( [leg] => 4 [eyes] => 2 ) [Cat] => Array ( [leg] => 3 [eyes] => 4 ) )";
0

3 Answers 3

3

You can use var_export to store parsable string as the above string give syntax error when executed with eval because that is not a valid array declaration syntax.

$array=array(1,2,3,4,5);
$b=var_export($array,true);
$c=eval("return $b;");
print_r($c);
Sign up to request clarification or add additional context in comments.

Comments

0

I dont think it should be in quotes. By, putting it within quotes, you are telling the compiler that it is a string. If it is PHP it should be like $array = array("Dog" => array("leg"=>4, "eyes" => 2),"Cat" => array("leg"=>3, "eyes" => 4));

Or is it like you have a string and want to convert the data in it into string???

Comments

0

You have got this array from var_export function

You can bring back your array like this.

<?php
$array="Array ( [Dog] => Array ( [leg] => 4 [eyes] => 2 ) [Cat] => Array ( [leg] => 3 [eyes] => 4 ) )";
$finalRes=eval("return $array;");
print_r($finalRes);
?>

You can use var_export to store parsable string as the above string give syntax error when executed with eval because that is not a valid array declaration syntax.

Definition: Eval () is used to evaluate the input string as PHP. It is like using the Echo () function in the sense that it outputs everything, except instead of outputting it as text, it outputs it as PHP code to be executed. One use of this is to store code in a database to execute later. Also Known As: Evaluate String Examples:

 <?php 
 $name = 'Joe';
 $name2 = 'Jim';
 $a = 'My friends are $name and $name2';
 print $a . "<br>"; 
 eval("\$a = \"$a\";"); 
 print $a . "<br>"; 
 ?> 

This would output My friends are $name and $name2 when first called with the print statement, but would output My friends are Joe and Jim when called the second time after running eval ()

Your can get the array from here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.