Hi,
I am not sure if this is possible...
suppose I have these paragraphs, <p> tags, and links, <a> tags,
<p>this is a sample paragraph 1.</p>
<p>this is a sample paragraph 2.</p>
<p>this is a sample paragraph 3 with a <a href="www.link.com">link 1</a></p>
<p>this is a sample paragraph 4 with a <a href="www.link.com">link 2</a></p>
and I want to embed the css style into these tags when you submit it, so it will output:
<p style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color: #000000; ">this is a sample paragraph 1.</p>
<p style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color: #000000; ">this is a sample paragraph 2.</p>
<p style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color: #000000; ">this is a sample paragraph 3 with a <a href="www.link.com" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color: #000000; ">link</a></p>
so I think I could use preg_replace(),
preg_replace("/<p\/>/si", "/<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color: #000000;\"\/>/si", $content);
preg_replace("/<a\/>/si", "/<a style=\"font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color: #000000;\"\/>/si", $content);
but I think my expressions are incorrect especially in the <a> tags bcos I have the url in them...
thanks so much if u have any ideas...
Many thanks!
Lau
preg replace: replacing html tags with inline css style
Moderator: General Moderators
-
lauthiamkok
- Forum Contributor
- Posts: 153
- Joined: Wed Apr 01, 2009 2:23 pm
- Location: Plymouth, United Kingdom
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: preg replace: replacing html tags with inline css style
Have a look at the example on this page:
http://uk2.php.net/manual/en/function.p ... .php#87944
Although this code is being used to convert BBCode into HTML tags, the important thing to notice is that it's preserving the tag's attributes as well as any other content contained within the tags.
HTH,
Mecha Godzilla
http://uk2.php.net/manual/en/function.p ... .php#87944
Although this code is being used to convert BBCode into HTML tags, the important thing to notice is that it's preserving the tag's attributes as well as any other content contained within the tags.
HTH,
Mecha Godzilla
Re: preg replace: replacing html tags with inline css style
Put the CSS rules in a stylesheet or <style>. There's no reason you should need to put them inline.