preg replace: replacing html tags with inline css style
Posted: Thu May 06, 2010 12:18 pm
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
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