Attack svg image with css and php include

Question:

I can't attack SVG image properties with php include. Would you have another method? Since I need to call the images from the database dynamically through include(). Here is a working example, when the svg image is in its pure code on the page in question.

<style>
    #produto > svg > g{ 
      fill: #fff;
    }
</style>
<html>
    <body>
        <div id="produto">
            <svg...>
                <g>..</g>
            </svg>
        </div>
    </body>
</html>

I would like it to work this way:

<style>
    #produto > svg > g{ 
      fill: #fff;
    }
</style>
<html>
    <body>
        <div id="produto">
            <?php include('image/my-img.svg');?>
        </div>
    </body>
</html>

I tried the methods of embedding images in sgv ( embed, object) and I was not successful.

Answer:

For you to import the svg image and still have access to its respective tags you can use the following code:

<?php echo file_get_contents("kiwi.svg"); ?>

This way you can reference the SVG elements via a CSS stylesheet file.

Scroll to Top
AllEscort