jwhite68 Posted September 25, 2007 Share Posted September 25, 2007 I want to be able to strip the MARGIN elements from the <P> tags. Currently, I use strip tags to remove the <P> elements completely, but have found that this results in a poorer display of the clients data, since its ignoring paragraphs. What I actually want to do is just ignore the MARGIN settings within the P tags. Does anyone know how I can achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/70595-strip-margin-from-p-tags/ Share on other sites More sharing options...
Lumio Posted September 25, 2007 Share Posted September 25, 2007 What is a MARGIN-element? Quote Link to comment https://forums.phpfreaks.com/topic/70595-strip-margin-from-p-tags/#findComment-354731 Share on other sites More sharing options...
jaymc Posted September 25, 2007 Share Posted September 25, 2007 str_replace("<p style=margin:4px;>", "<p>" $strings); I dunno is that what you want? That will be fine providing its margin is always the same and doesnt conflict with others p's you have where you want the margin Quote Link to comment https://forums.phpfreaks.com/topic/70595-strip-margin-from-p-tags/#findComment-354733 Share on other sites More sharing options...
jwhite68 Posted September 25, 2007 Author Share Posted September 25, 2007 The source text with the margin information can vary. Its containted within a description field, which my customers provide in HTML format. Here is one example. But the margin parameters could be set to anything, and the margin info could appear anywhere in the string. So it needs to be removed from every occurence in the string wherever it is. <P class=MsoNormal style=MARGIN: 0in 0in 0pt; Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/70595-strip-margin-from-p-tags/#findComment-354740 Share on other sites More sharing options...
jwhite68 Posted September 25, 2007 Author Share Posted September 25, 2007 What I think would solve the issue is to strip any occurences of class=".." and style=".." from within any <p> tags. Since those classes and styles can contain anything from my clients, can someone suggest a way I can achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/70595-strip-margin-from-p-tags/#findComment-354764 Share on other sites More sharing options...
jaymc Posted September 25, 2007 Share Posted September 25, 2007 It sounds quite tricky, you can probably do it using a few explodes or str_replaces but as I said, quite trick How do the margin elements get in there ni the first place, maybe you should look at it that way. Kill it before it gets in and merged with your p tags Quote Link to comment https://forums.phpfreaks.com/topic/70595-strip-margin-from-p-tags/#findComment-354772 Share on other sites More sharing options...
Lumio Posted September 25, 2007 Share Posted September 25, 2007 preg_replace("/\<p.*?style=.*?margin:.*?;.*\>/", "<p>" $strings); Quote Link to comment https://forums.phpfreaks.com/topic/70595-strip-margin-from-p-tags/#findComment-354776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.