Author Topic: Strip margin from p tags  (Read 583 times)

0 Members and 1 Guest are viewing this topic.

Offline jwhite68Topic starter

  • Enthusiast
  • Posts: 170
  • Gender: Male
    • View Profile
    • Inspired Ideas Ltd
Strip margin from p tags
« on: September 25, 2007, 04:08:04 AM »
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?

Offline Lumio

  • Devotee
  • Posts: 677
  • Gender: Male
    • View Profile
Re: Strip margin from p tags
« Reply #1 on: September 25, 2007, 04:20:59 AM »
What is a MARGIN-element?
greetings
-Lumio

I don't test most of my posted code

Offline jaymc

  • Addict
  • Posts: 1,528
  • Gender: Male
    • View Profile
    • SEO Agency
Re: Strip margin from p tags
« Reply #2 on: September 25, 2007, 04:25:22 AM »
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
I would love to change the world, but they won't give me the source code

SEO Agency

Offline jwhite68Topic starter

  • Enthusiast
  • Posts: 170
  • Gender: Male
    • View Profile
    • Inspired Ideas Ltd
Re: Strip margin from p tags
« Reply #3 on: September 25, 2007, 04:32:34 AM »
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?




Offline jwhite68Topic starter

  • Enthusiast
  • Posts: 170
  • Gender: Male
    • View Profile
    • Inspired Ideas Ltd
Re: Strip margin from p tags
« Reply #4 on: September 25, 2007, 05:14:04 AM »
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?

Offline jaymc

  • Addict
  • Posts: 1,528
  • Gender: Male
    • View Profile
    • SEO Agency
Re: Strip margin from p tags
« Reply #5 on: September 25, 2007, 05:30:57 AM »
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
I would love to change the world, but they won't give me the source code

SEO Agency

Offline Lumio

  • Devotee
  • Posts: 677
  • Gender: Male
    • View Profile
Re: Strip margin from p tags
« Reply #6 on: September 25, 2007, 05:43:01 AM »
preg_replace("/\<p.*?style=.*?margin:.*?;.*\>/""<p>" $strings);
greetings
-Lumio

I don't test most of my posted code