I am trying to write a php script that will take find the path of a webpage or a url, and convert the css from the server or local folder to inline code. I've looked pretty much all over the internet and looked for many solutions that could help me do this and done helped so far.

I have several <div>'s in my page all linking to a css code called general.css
For e.g.

<div class="sys_main_logo" style="">
		
<div class="sys_ml">
            
<div class="sys_ml_wrapper">

I want it to be able to convert to the properties of the css it's linked to to inline code
for e.g.

<div style="position: relative; z-index: 56; background-color: #f4f4f4;>

Is this possible to write, can somebody assist me with this please? Thanks

Anything is possible. In it's most basic version a simple replace will do. Don't be mislead, CSS is a cascading style and can inherit from it's parent or another class. That makes it much more difficult.

First you'll need a script to parse a css file, so you can match tags, id's and classes.

I think the best way for you to start, is to limit the scope of what you allow in your html and css, and work from there.

It's because i'm trying to send the webpage as an e-mail, and i will have future webpages to send as e-mails as well so i need a PHP code that will take out the <a href> links and turn all css links into inline style code. I already have a code where it removes all <a href> links. Can i have help with this please?

Wouldn't it be easier to make an email template, as not every email client supports every css ?

Anyway, start with a parser for css. Something that opens the css file and cuts it to pieces.

Wouldn't it be easier to make an email template, as not every email client supports every css ?

Anyway, start with a parser for css. Something that opens the css file and cuts it to pieces.

Can you guide me through doing that? Because i am brand new to PHP

Have a look at smarty.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.