1

I wander why my code produce a wrong output.

$array = require 'http://vilavaleaprahovei.ro/kimea/allMarks.php';
$output = array_keys($array);
$option = '';
foreach ($output as $val) {
    $option .= "<option>$val</option>";
}
print_r($option);

Expected result is:

<option>ALCAR STAHLRAD</option>
<option>ENZO</option>
<option>DEZENT</option>
...........

Thank you in advance!

5
  • what are you getting after printing $array. Commented Oct 24, 2018 at 9:01
  • My result is here: vilavaleaprahovei.ro/kimea/mark.php Commented Oct 24, 2018 at 9:01
  • require doesn't work in the way it looks like you think it does Commented Oct 24, 2018 at 9:01
  • what does the print_r($output); give? Commented Oct 24, 2018 at 9:15
  • instead of require you should do following: $array = file_get_contents('http://vilavaleaprahovei.ro/kimea/allMarks.php'); $array = unserialize($array); Commented Oct 24, 2018 at 9:18

3 Answers 3

2

ensure you have allow_url_include = On in your php.ini

if allMarks.php is a php file where you declare and return an array you should open the php script tag <?php first and use the return keyword as follow:

<?php
return array (
  'ALCAR STAHLRAD' => 
  array ( ...
Sign up to request clarification or add additional context in comments.

Comments

1

Try this I hope it will works :

$data = array('ALCAR STAHLRAD' => array('diametru' => array(0 => 15, 6 => 16, 9 => 14, 14 => 13, 20 => 17, 468 => 20,), 'latime' => array(0 => 6, 9 => 5, 10 => 4, 27 => 7, 501 => 3,), 'pcd' => array(0 => 15, 6 => 16, 9 => 14, 14 => 13, 20 => 17, 468 => 20,), 'pcd1' => array(0 => 15, 6 => 16, 9 => 14, 14 => 13, 20 => 17, 468 => 20,), 'et' => array(0 => 15, 6 => 16, 9 => 14, 14 => 13, 20 => 17, 468 => 20,), 'cb' => array(0 => 15, 6 => 16, 9 => 14, 14 => 13, 20 => 17, 468 => 20,),), 'ENZO' => array('diametru' => array(0 => 16, 2 => 17, 3 => 15, 10 => 14, 14 => 18,), 'latime' => array(0 => 6, 1 => 7, 10 => 5, 35 => 8,), 'pcd' => array(0 => 16, 2 => 17, 3 => 15, 10 => 14, 14 => 18,), 'pcd1' => array(0 => 16, 2 => 17, 3 => 15, 10 => 14, 14 => 18,), 'et' => array(0 => 16, 2 => 17, 3 => 15, 10 => 14, 14 => 18,), 'cb' => array(0 => 16, 2 => 17, 3 => 15, 10 => 14, 14 => 18,),), 'DEZENT' => array('diametru' => array(0 => 17, 1 => 16, 6 => 15, 24 => 18, 46 => 14, 80 => 19, 159 => 20,), 'latime' => array(0 => 7, 6 => 6, 20 => 8, 63 => 5, 120 => 4, 159 => 9,), 'pcd' => array(0 => 17, 1 => 16, 6 => 15, 24 => 18, 46 => 14, 80 => 19, 159 => 20,), 'pcd1' => array(0 => 17, 1 => 16, 6 => 15, 24 => 18, 46 => 14, 80 => 19, 159 => 20,), 'et' => array(0 => 17, 1 => 16, 6 => 15, 24 => 18, 46 => 14, 80 => 19, 159 => 20,), 'cb' => array(0 => 17, 1 => 16, 6 => 15, 24 => 18, 46 => 14, 80 => 19, 159 => 20,),), 'DOTZ' => array('diametru' => array(0 => 17, 1 => 15, 3 => 18, 5 => 16, 6 => 19, 65 => 20,), 'latime' => array(0 => 7, 1 => 6, 2 => 8, 71 => 9,), 'pcd' => array(0 => 17, 1 => 15, 3 => 18, 5 => 16, 6 => 19, 65 => 20,), 'pcd1' => array(0 => 17, 1 => 15, 3 => 18, 5 => 16, 6 => 19, 65 => 20,), 'et' => array(0 => 17, 1 => 15, 3 => 18, 5 => 16, 6 => 19, 65 => 20,), 'cb' => array(0 => 17, 1 => 15, 3 => 18, 5 => 16, 6 => 19, 65 => 20,),), 'AEZ' => array('diametru' => array(0 => 16, 1 => 17, 5 => 18, 10 => 19, 28 => 20, 106 => 21, 157 => 22,), 'latime' => array(0 => 7, 1 => 8, 16 => 9, 105 => 6, 106 => 11, 114 => 10,), 'pcd' => array(0 => 16, 1 => 17, 5 => 18, 10 => 19, 28 => 20, 106 => 21, 157 => 22,), 'pcd1' => array(0 => 16, 1 => 17, 5 => 18, 10 => 19, 28 => 20, 106 => 21, 157 => 22,), 'et' => array(0 => 16, 1 => 17, 5 => 18, 10 => 19, 28 => 20, 106 => 21, 157 => 22,), 'cb' => array(0 => 16, 1 => 17, 5 => 18, 10 => 19, 28 => 20, 106 => 21, 157 => 22,),),);
// Above array is your data
$option = '';
foreach ($data as $key => $val) {
    $option .= "<option>$key</option>";
}
print_r(htmlentities($option));

Comments

-1

the problem you are facing is that you want to print html without rendering it on html so you should be using

 foreach ($output as $val) {
    $option .= "&lt;option&gt;$val&lt;/option&gt; </br>";
}

instead of

foreach ($output as $val) {
    $option .= "<option>$val</option>";
}

2 Comments

Now on server is: $array = require 'vilavaleaprahovei.ro/kimea/allMarks.php'; $output = array_keys($array); $option = ''; foreach ($output as $val) { $option .= "&lt;option&amp;$val&lt;/option&amp$val&lt;/br&amp;"; } print_r($option); But result is the same: vilavaleaprahovei.ro/kimea/mark.php
can you print echo "<pre>"; print_r($array); instead of print_r($option);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.