Attack svg image with css and include php

Asked

Viewed 495 times

3

I cannot attack the properties of the SVG image with include php. Is there another method? Therefore, I need to call the bank images dynamically through include(). Here is a functional 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 wish it worked 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 inclusion of images in sgv ( embed, Object) and was unsuccessful.

  • what exactly is in that file . svg?

  • is an array, exported in svg image, with tags, svg, g and path, which attribute css properties

  • as you did when you tried to <object>? something like this doesn’t work? <object data="<?php include('image/my-img.svg');?>" type="image/svg+xml" id="id_qualquer" />

  • No effect, just nothing appears, as in <?php include('image/my-img.svg');?>

  • the file path is correct? test this: <?php echo file_exists('image/my-img.svg')? 'ok': 'ng';?>

  • I tested and gave ok! I think include php simply doesn’t recognize the . svg extension...

  • the extension does not have to do.. can be a . exe that php normally includes the content. Have you tried seeing the result by the browser source code.. in Chrome , run the php page normally and then press CTRL+U. Probably you will find the <svg> in the code

  • by source code does not appear svg, similarly in front-end, the page code stops at include and does not display anything from then on...

  • A fatal type error is occurring. Check the log and error view options to mitigate the actual problem. This can help you set up: http://answall.com/a/117145/4793

Show 4 more comments

1 answer

1

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

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

So you can reference the elements SVG by means of a style sheet file CSS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.