Кемеровские программисты php общаются здесь
Гость
Поведение DOMDocument различается в различных конфигурациях PHP.
Сообщение
Гость » 11 мар 2024, 13:49
Вот пример кода, который ведет себя по-разному с
$DOMDocument = new DOMDocument;
$elementMarkup = mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8');
$DOMDocument->loadHTML($elementMarkup);
$DOMDocument->removeChild($DOMDocument->doctype);
$DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);
The incorrect behavior appears to
Код: Выделить всё
$DOMDocument->firstChild->firstChild->firstChild
It should be
(Nodenames from xdebug: html-head-meta) and phpbrew's php works fine.
But dockerized php cathes
(Nodenames: html-#text-null).
Dockerfile
Код: Выделить всё
FROM php:7.1-fpm-alpine
RUN apk upgrade --update && apk --no-cache add \
bash nodejs autoconf file g++ gcc binutils isl libatomic libc-dev musl-dev make re2c libstdc++ libgcc libcurl \
curl-dev binutils-libs mpc1 mpfr3 gmp libgomp coreutils freetype-dev libjpeg-turbo-dev libltdl libmcrypt-dev \
libpng-dev openssl-dev libxml2-dev expat-dev icu-dev libxslt libxslt-dev
RUN docker-php-ext-install -j$(nproc) iconv mysqli pdo pdo_mysql curl bcmath mcrypt mbstring json xml zip opcache intl xsl \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN apk --no-cache add libintl gettext-dev
RUN docker-php-ext-install -j$(nproc) gettext
RUN apk add --no-cache $PHPIZE_DEPS \
&& echo no | pecl install redis \
&& docker-php-ext-enable redis
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug
CMD ["php-fpm"]
Источник:
https://stackoverflow.com/questions/496 ... igurations
1710154153
Гость
Вот пример кода, который ведет себя по-разному с [list] [*][code]phpbrew's php 7.1.5[/code] [*] [code]docker container with php 7.1.15[/code] [code]$elementMarkup = ' Title '; [/code] $DOMDocument = new DOMDocument; $elementMarkup = mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8'); $DOMDocument->loadHTML($elementMarkup); $DOMDocument->removeChild($DOMDocument->doctype); $DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild); [/list] The incorrect behavior appears to [code]$DOMDocument->firstChild->firstChild->firstChild[/code] It should be [code]meta[/code](Nodenames from xdebug: html-head-meta) and phpbrew's php works fine. But dockerized php cathes [code]null[/code](Nodenames: html-#text-null). Dockerfile [code]FROM php:7.1-fpm-alpine RUN apk upgrade --update && apk --no-cache add \ bash nodejs autoconf file g++ gcc binutils isl libatomic libc-dev musl-dev make re2c libstdc++ libgcc libcurl \ curl-dev binutils-libs mpc1 mpfr3 gmp libgomp coreutils freetype-dev libjpeg-turbo-dev libltdl libmcrypt-dev \ libpng-dev openssl-dev libxml2-dev expat-dev icu-dev libxslt libxslt-dev RUN docker-php-ext-install -j$(nproc) iconv mysqli pdo pdo_mysql curl bcmath mcrypt mbstring json xml zip opcache intl xsl \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gd RUN apk --no-cache add libintl gettext-dev RUN docker-php-ext-install -j$(nproc) gettext RUN apk add --no-cache $PHPIZE_DEPS \ && echo no | pecl install redis \ && docker-php-ext-enable redis RUN apk add --no-cache $PHPIZE_DEPS \ && pecl install xdebug \ && docker-php-ext-enable xdebug CMD ["php-fpm"] [/code] Источник: [url]https://stackoverflow.com/questions/49600569/domdocument-behaviour-differs-on-various-php-configurations[/url]