-4

screenshot

Hello, as you can see in the screenshot, when i extract data from a site with PHP Simple HTML DOM Parser. I have this result , so i would like to convert this data to a real array to have the real control and the opportunity to access with $array['label']

<?php include_once('simple_html_dom.php'); ?>
<!DOCTYPE html>

<html>
<head>

<title> HTML DOM Parser</title>
</head>
<body>
<?php
header('Content-Type: text/html; charset=utf-8');
set_time_limit(0);
$html=file_get_html('https://www.monreseauplus.com/villes/');
$array[]=array();
$array3[]=array();
foreach($html->find('.ul. li.cat-item a') as $elements){
    $array2=$elements->title;
    $array=str_replace(':','=>',$array2);
    $arraynospec=htmlspecialchars_decode($array);
    var_dump($arraynospec);
    }
?>
</body>
</html>
5
  • 2
    Screenshots aren't a very good way of sharing code. It's better to put it in a code block. Commented Nov 2, 2017 at 20:17
  • 2
    A real array? You will need to suuply more information than this, and documented examples of what you have tried, and researched. And yes, a screenshot of a mess is not really helpful for others to be helpful. Commented Nov 2, 2017 at 20:18
  • Check this out: stackoverflow.com/questions/684553/… Commented Nov 2, 2017 at 20:19
  • Maybe this web site can provide you JSON data Commented Nov 2, 2017 at 20:23
  • This is my code : $array2=$elements->title; $array=str_replace(':','=>',$array2); $arraynospec=htmlspecialchars_decode($array); $json = json_encode($arraynospec); var_dump(json_decode($json)); Commented Nov 2, 2017 at 20:36

1 Answer 1

0

So it looks like you are trying to string manipulate JSON to try to make some sort of associative array. Replacing the : with => is not the right move here...

    <?php include_once('simple_html_dom.php'); ?>
    <!DOCTYPE html>

    <html>
    <head>

    <title> HTML DOM Parser</title>
    </head>
    <body>
    <?php
    header('Content-Type: text/html; charset=utf-8');
    set_time_limit(0);
    $html=file_get_html('https://www.monreseauplus.com/villes/');
    $array[]=array();
    $array3[]=array();
    foreach($html->find('.ul. li.cat-item a') as $elements){
        $array2=$elements->title;
        $array=json_decode($array2,true)
        $arraynospec=htmlspecialchars_decode($array);
        var_dump($arraynospec);
    }
    ?>
    </body>
    </html>

Try that

This is the problem: $array=str_replace(':','=>',$array2); Looks like it was already in JSON!

Sign up to request clarification or add additional context in comments.

14 Comments

firstly , thank you for your reply but this doesn't work for me as you can view in this screen :img4.hostingpics.net/pics/171183oop.png . i use var_dump to show data in this example
Did you try unserialize?
when i use unserialize i have this error : unserialize(): Error at offset 0 of 54 bytes
check this out stackoverflow.com/questions/10152904/… Looks like it's due to special characters
i use base64_encode(serialize($data)); and $array3=unserialize(base64_decode($string)) but this shows me the same result : img4.hostingpics.net/pics/171183oop.png
|

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.