1
**Как я могу убрать текст с парсера вот код вывод
Array
(
    [article] => SimpleXMLElement Object
        (
            [0] => 909
        )

    [name] => SimpleXMLElement Object
        (
            [0] => Практический маркетинг
        )

    [end] => SimpleXMLElement Object
        (
            [0] => 2020-10-26T20:00:00-05:00
        )

    [price] => SimpleXMLElement Object
        (
            [0] => 5600
        )

    [lesson] => SimpleXMLElement Object
        (
            [0] => 12
        )

    [start] => SimpleXMLElement Object
        (
            [0] => 2020-09-17T19:00:00-05:00
        )

)
и сделать [name] => Практический маркетинг и так далее**



    public function startParsing() {

        $xml = simplexml_load_file('https://ссылка');

        foreach ($xml as $worker) {
            $id = $worker->landing->id;
            $name = $worker->landing->name;
            $start_datetime = $worker->landing->start_datetime;
            $end_datetime = $worker->landing->end_datetime;
            $lessons_count = $worker->landing->lessons_count;
            $price = $worker->landing->price;


            if (isset ($id[0]) && isset ($price[0])){
                $parser = array(
                    'article' => $id[0],
                    'name' => $name,
                    'end' => $end_datetime[0],
                    'price' => $price[0],
                    'lesson' => $lessons_count,
                    'start' => $start_datetime,

                );
                print_r($parser);
//                $this->processProducts($parser);
            } else {
                continue;
            }
        }
    }

1 ответ 1

1

Приведите значение SimpleXMLElement к строковому типу

public function startParsing()
{

    $xml = simplexml_load_file('https://ссылка');
    foreach ($xml as $worker) {
        $id = $worker->landing->id;
        $name = $worker->landing->name;
        $start_datetime = $worker->landing->start_datetime;
        $end_datetime = $worker->landing->end_datetime;
        $lessons_count = $worker->landing->lessons_count;
        $price = $worker->landing->price;
        if (isset ($id[0]) && isset ($price[0])) {
            continue;
        }
        $parser = array(
            'article' => (string)$id[0],
            'name' => (string)$name,
            'end' => (string)$end_datetime[0],
            'price' => (string)$price[0],
            'lesson' => (string)$lessons_count,
            'start' => (string)$start_datetime,
        );
        print_r($parser);
        //$this->processProducts($parser);
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.