How can DOMDocument be utilized in PHP to edit SVG files effectively?

To edit SVG files effectively in PHP, you can utilize the DOMDocument class to parse the SVG file, make necessary modifications to the XML structure, and then save the updated SVG content back to a file.

// Load the SVG file
$svgFile = 'path/to/your/svg/file.svg';
$doc = new DOMDocument();
$doc->load($svgFile);

// Make modifications to the SVG content
$svgElement = $doc->getElementsByTagName('svg')->item(0);
$svgElement->setAttribute('width', '100');
$svgElement->setAttribute('height', '100');

// Save the updated SVG content back to a file
$doc->save('path/to/save/updated/svg/file.svg');