Jump to content

Recommended Posts

It's just another chunk of HTML.

<?php

 echo "<h1>Sample SVG<?h1>
        <div style='margin-top: 50px;'>";
    
 readfile("svg/sample1.svg");
    
 echo "</div>";
?>

sample1.svg

<svg width='200' height='200' viewBox='0 0 200 200'>              
<defs>                                                                    
    <style type='text/css'>                                               
        .light { stop-color: #F7F7F7; }                                                   
        .mid   { stop-color: #777777; }                                                   
        .dark  { stop-color: #070707; }                                                   
        .grad  { fill: url(#grad1) }                                                      
        .grad2 { fill: url(#grad2) }                                                      
    </style>                                                                              
    <linearGradient id='grad1' x1='0' y1='0' x2='1' y2='1'>                               
        <stop offset='10%' class='light' />                                               
        <stop offset='90%' class='dark' />
    </linearGradient>
    <linearGradient id='grad2' x1='1' y1='1' x2='0' y2='0' >
        <stop offset='10%' class='light' />
        <stop offset='90%' class='dark' />
    </linearGradient>
    
</defs>
<rect x='0' y='0' width='200' height='200' fill='black' />
<circle cx='100' cy='100' r='80' class='grad' />
<circle cx='100' cy='135' r='40' class='grad2' />
<circle cx='100' cy='135' r='30' fill='black' />
<circle cx='100' cy='46' r='20' class='grad2' />
<circle cx='100' cy='46' r='13' fill='black' />
</svg>

 

Link to comment
https://forums.phpfreaks.com/topic/314901-svg-in-php-file/#findComment-1597081
Share on other sites

Thanks so much for getting back to me so quickly! I'm pretty new to this. Can you please tell me where to paste the code? As soon as I add the svg tag to my php file it breaks.

Here is the code for the svg...

<button class="md:hidden rounded-lg focus:outline-none focus:shadow-outline" @click="open = !open"> <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6"> <path x-show="!open" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path> <path x-show="open" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> </button>

Link to comment
https://forums.phpfreaks.com/topic/314901-svg-in-php-file/#findComment-1597086
Share on other sites

I got better results when I added width and height attributes to your svg

 echo '<button class="md:hidden rounded-lg focus:outline-none focus:shadow-outline" @click="open = !open"> 
 <svg fill="currentColor" width="50" height="50" viewBox="0 0 20 20" class="w-6 h-6"> <path x-show="!open" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path> <path x-show="open" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg>
 </button> ';

image.png.b3a8c59d2671c007f82c2762477ec2e3.png

Link to comment
https://forums.phpfreaks.com/topic/314901-svg-in-php-file/#findComment-1597089
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.