Reply LinkBack Thread Tools Search this Thread
Old 01-04-2008, 06:04   #1 (permalink)
d*d
Senior Member
 
d*d's Avatar
 
Join Date: Oct 2004
Location: Bristol
Posts: 2,804
removing Html tag attributes in php

anyone know a good way to do this? got a CMS which is accepting style attributes for the <p> tag, which then override my css styles on the site. Need to keep the <p> tag just remove all it's attrinbutes;

so
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal">

becomes

<p>
  Reply With Quote
Old 01-04-2008, 06:55   #2 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,287
You mean the CMS is creating this styling in the out put and you want to stop it?

If that is the case you need to search the source code of the CMS for eg. style="margin and just remove that styling in the instances it appears.

If no results try style=\"margin in case is escaped in code.

If I understand you correctly?
__________________
  Reply With Quote
Old 01-04-2008, 07:42   #3 (permalink)
d*d
Senior Member
 
d*d's Avatar
 
Join Date: Oct 2004
Location: Bristol
Posts: 2,804
The CMS itself isn't, copying into a textbox from word is. I think I may need a regular expression or similar to check if a <p> tag has anything inside other than 'p'
  Reply With Quote
Old 02-04-2008, 01:38   #4 (permalink)
gk
geek
 
gk's Avatar
 
Join Date: Oct 2006
Location: *.everywhere
Posts: 204
Send a message via ICQ to gk Send a message via AIM to gk Send a message via MSN to gk Send a message via Yahoo to gk
Code:
$string = preg_replace('`<(/?[a-zA-Z]+)[^>]*>`','',$string)
__________________
Quote:
"Why reinvent the wheel"? Simply because it's not round enough and I don't like the treads.
  Reply With Quote
Old 02-04-2008, 01:41   #5 (permalink)
seen.to
unusual suspect ™
 
seen.to's Avatar
 
Join Date: Jul 2004
Location: DE, USA
Posts: 2,511
Word's a cunt.

Copy into notepad first (tell your clients to) then paste into the CMS's HTML editor. Don't even bother trying to clear out the Word shite that's added through code as there are so many versions of Word that the content may come from and they all tow their own crap behind them.
__________________
  Reply With Quote
Old 02-04-2008, 04:25   #6 (permalink)
d*d
Senior Member
 
d*d's Avatar
 
Join Date: Oct 2004
Location: Bristol
Posts: 2,804
finally used preg_replace('/<p\b[^>]*+>/', '', $string);

@seen to, I've used strip_tags to get rid of anything else word may chuck at me, the <p> tag was an exception (along with bold and italic),so hopefully this should do it - Word is a cunt though
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8