Php xmlwriter extension missing

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLWriter not found #14

XMLWriter not found #14

Comments

I have just installed php-marc via composer but when I try to use it, it logs:

PHP Fatal error: Uncaught Error: Class 'XMLWriter' not found in /home/user/project_test/vendor/pear/file_marc/File/MARCBASE.php:95 

The installation process went well, I tried to regenerate autoloading but nothing helped.

The example I am trying to use:

require __DIR__. '/vendor/autoload.php'; use Scriptotek\Marc\Collection; $collection = Collection::fromFile('./tmp/exportvuf.mrc'); foreach ($collection as $record) < echo $record->getField('001')->getData() . "\n"; >

PHP 7.2.19
Composer 1.9.0
Ubuntu 19.04

Читайте также:  Java android массив строк

The text was updated successfully, but these errors were encountered:

@danmichaelo, that was my very first attempt to make it to work.

I have php7.2-xml installed.

xmlrpc_error_number => 0 => 0 xmlrpc_errors => Off => Off libxml 

From the askubuntu thread, I am not sure what it should return in the case php-xml is ready. Or should I enable it or so?

Hm, seems like xmlwriter is a separate extension, but it got installed by default for me. Here’s what I got (on Red Hat):

php -i | grep -i "xml" /etc/opt/rh/rh-php72/php.d/20-simplexml.ini, /etc/opt/rh/rh-php72/php.d/20-xml.ini, /etc/opt/rh/rh-php72/php.d/20-xmlwriter.ini, /etc/opt/rh/rh-php72/php.d/30-xmlreader.ini xmlrpc_error_number => 0 => 0 xmlrpc_errors => Off => Off DOM/XML => enabled DOM/XML API Version => 20031129 libxml Version => 2.9.1 libxml libXML support => active libXML Compiled Version => 2.9.1 libXML Loaded Version => 20901 libXML streams => enabled mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text/|application/xhtml\+xml) SimpleXML Simplexml support => enabled xml XML Support => active XML Namespace Support => active libxml2 Version => 2.9.1 xmlreader XMLReader => enabled xmlwriter XMLWriter => enabled libxslt compiled against libxml Version => 2.9.1 

The XMLWriter => enabled line shows that the xmlwriter extension is enabled.

Perhaps there’s a php7.2-xmlwriter package?

I omitted the -i argument for grep:

xmlrpc_error_number => 0 => 0 xmlrpc_errors => Off => Off libxml libXML support => active libXML Compiled Version => 2.9.4 libXML Loaded Version => 20904 libXML streams => enabled 

Yeah, I did that at first too. But indeed seems like you’re missing some php extensions. Try installing php7.2-xmlwriter . You might also need php7.2-dom and php7.2-simplexml , not sure.

In Ubuntu, it seems apt has php7.2-xmlwriter and php7.2-xml associated to php7.2-xml .

In the PHP Manual, there is:

The XMLWriter extension was initially a PECL extension for PHP 5. It was later added to the PHP source (bundled) as of PHP 5.1.2. This extension is enabled by default.

This could be the problem why I don’t see any configs, modules or extensions. I guess it should work without any additional configuration.

Hm, yeah, it should be enabled by default. How did you install php?

In that case it should be enough with

On a fresh Ubuntu 19 virtual machine I then get the following,

$ php -i | grep -i xml /etc/php/7.2/cli/conf.d/15-xml.ini, /etc/php/7.2/cli/conf.d/20-simplexml.ini, /etc/php/7.2/cli/conf.d/20-xmlreader.ini, /etc/php/7.2/cli/conf.d/20-xmlwriter.ini, xmlrpc_error_number => 0 => 0 xmlrpc_errors => Off => Off DOM/XML => enabled DOM/XML API Version => 20031129 libxml Version => 2.9.4 libxml libXML support => active libXML Compiled Version => 2.9.4 libXML Loaded Version => 20904 libXML streams => enabled SimpleXML Simplexml support => enabled xml XML Support => active XML Namespace Support => active libxml2 Version => 2.9.4 xmlreader XMLReader => enabled xmlwriter XMLWriter => enabled libxslt compiled against libxml Version => 2.9.4 

If you do not get XMLWriter => enabled at this point, the must be something odd with your setup.

Источник

How to enable xmlwriter after php having been compiled?

The PHP XMLWriter extension provides a simple and efficient way to create XML documents. However, in order for the extension to be used, it must first be enabled after PHP has been compiled. If the XMLWriter extension is not enabled, attempting to use it will result in a «Fatal error: Class ‘XMLWriter’ not found» or similar error message. There are a few different ways to enable the extension, depending on your specific setup.

Method 1: Use the —enable-xmlwriter option when configuring PHP

To enable the xmlwriter extension in PHP after it has been compiled, you can use the —enable-xmlwriter option when configuring PHP. Here are the steps to do it:

  1. Download the PHP source code from the official website and extract it to a directory.
  2. Open a terminal and navigate to the directory where the PHP source code is located.
  3. Run the following command to configure PHP with the —enable-xmlwriter option:
./configure --enable-xmlwriter

Now, the xmlwriter extension should be enabled in PHP.

Here is an example of how to use the xmlwriter extension in PHP:

// Create a new XML writer object $xml = new XMLWriter(); // Set the output file to stdout $xml->openURI('php://stdout'); // Start the document $xml->startDocument('1.0', 'UTF-8'); // Create an element with some attributes $xml->startElement('book'); $xml->writeAttribute('id', '1'); $xml->writeAttribute('isbn', '978-3-16-148410-0'); // Add some child elements $xml->startElement('title'); $xml->text('The Hitchhiker\'s Guide to the Galaxy'); $xml->endElement(); $xml->startElement('author'); $xml->text('Douglas Adams'); $xml->endElement(); // End the book element $xml->endElement(); // End the document $xml->endDocument();

This code will output the following XML:

 book id="1" isbn="978-3-16-148410-0"> title>The Hitchhiker's Guide to the Galaxytitle> author>Douglas Adamsauthor> book>

The XMLWriter class provides a simple and efficient way to generate XML documents in PHP. The startElement , writeAttribute , and text methods are used to create the structure and content of the XML document. The openURI , startDocument , and endDocument methods are used to set the output file and start and end the XML document.

Method 2: Use the —with-xmlwriter option when configuring PHP

To enable the xmlwriter extension in PHP, you can use the —with-xmlwriter option when configuring PHP during compilation. Here are the steps to follow:

  1. Download the PHP source code from the official website and extract it to a directory.
  2. Open a terminal window and navigate to the directory where the extracted PHP source code is located.
  3. Run the following command to configure PHP with the xmlwriter extension:

After completing these steps, the xmlwriter extension should be enabled in PHP. You can verify this by running the following code:

 if (extension_loaded('xmlwriter'))  echo 'xmlwriter extension is enabled'; > else  echo 'xmlwriter extension is not enabled'; > ?>

This code will output «xmlwriter extension is enabled» if the extension is enabled, or «xmlwriter extension is not enabled» if it is not enabled.

You can use the xmlwriter extension in your PHP code to create XML documents. Here is an example:

 // Create a new XMLWriter object $xml = new XMLWriter(); // Set the output file path $xml->openURI('output.xml'); // Start the document $xml->startDocument('1.0', 'UTF-8'); // Start the root element $xml->startElement('root'); // Add a child element $xml->writeElement('child', 'Hello World!'); // End the root element $xml->endElement(); // End the document $xml->endDocument(); // Output the XML echo $xml->outputMemory(); ?>

This code will create an XML document with a root element and a child element containing the text «Hello World!». The output will be written to a file named «output.xml».

Method 3: Use the php.ini file to enable the extension

To enable the xmlwriter extension in PHP, you can use the php.ini file. Here are the steps to follow:

  1. Locate your php.ini file. You can find the location of your php.ini file by running the following command in your terminal:

This will display the location of your php.ini file.

  1. Save the changes to your php.ini file and restart your web server.
  2. To verify that the xmlwriter extension is enabled, create a new PHP file with the following code:
 if (extension_loaded('xmlwriter'))  echo 'xmlwriter is enabled'; > else  echo 'xmlwriter is not enabled'; >
  1. Open the PHP file in your web browser. If the xmlwriter extension is enabled, you should see the message «xmlwriter is enabled» displayed on the page.

That’s it! You have successfully enabled the xmlwriter extension in PHP using the php.ini file.

Method 4: Use the dl() function to load the extension at runtime

To enable the xmlwriter extension in PHP after it has been compiled, you can use the dl() function to load the extension at runtime. Here are the steps to do it:

if (!extension_loaded('xmlwriter')) 
 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')  dl('php_xmlwriter.dll'); > else  dl('xmlwriter.so'); >
 $writer = new XMLWriter(); $writer->openMemory(); $writer->startDocument(); $writer->startElement('root'); $writer->writeElement('item', 'value'); $writer->endElement(); $writer->endDocument(); echo $writer->outputMemory();

Here is the complete code:

if (!extension_loaded('xmlwriter'))  if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')  dl('php_xmlwriter.dll'); > else  dl('xmlwriter.so'); > > $writer = new XMLWriter(); $writer->openMemory(); $writer->startDocument(); $writer->startElement('root'); $writer->writeElement('item', 'value'); $writer->endElement(); $writer->endDocument(); echo $writer->outputMemory();

This code will output the following XML document:

Note that the dl() function is deprecated in PHP 7.2 and removed in PHP 8.0. So, it’s better to compile PHP with the required extensions or use a different approach to enable extensions at runtime.

Method 5: Use the Windows Registry to enable the extension

To enable the xmlwriter extension in PHP after it has been compiled, you can use the Windows Registry. Follow these steps:

  1. Open the Registry Editor by pressing Win + R and typing regedit .
  2. Navigate to the HKEY_LOCAL_MACHINE\SOFTWARE\PHP key.
  3. Create a new key called Extensions\xmlwriter .
  4. Create a new string value called extension_dir and set its value to the path of your PHP extensions directory (e.g. C:\php\ext ).
  5. Create a new string value called extension and set its value to php_xmlwriter.dll .
  6. Restart your web server (e.g. Apache) for the changes to take effect.

Here’s an example PHP script that uses the xmlwriter extension to create an XML file:

 // Create a new XMLWriter object $xml = new XMLWriter(); // Open the XML document $xml->openURI('output.xml'); $xml->startDocument('1.0', 'UTF-8'); // Create the root element $xml->startElement('root'); // Add some child elements $xml->startElement('child'); $xml->text('Hello, world!'); $xml->endElement(); // Close the root element $xml->endElement(); // Close the XML document $xml->endDocument(); ?>

In this example, we first create a new XMLWriter object and open an XML file for writing. We then create a root element called root and add a child element called child with some text content. Finally, we close the root element and the XML document.

Note that the XMLWriter class provides many other methods for creating and manipulating XML documents. Refer to the PHP documentation for more information.

Источник

Оцените статью