terrycody
Elite Member
- Sep 29, 2012
- 6,058
- 3,133
I don't know programming at all! But I am using a wordpress PHP plugin, it seems use some regular expression to find and replace the HTML tags in the article.
So I meet some problems when using it, please give me some tips if you know how to solve these problems! Thank you in advance!
Question 1:
Say, if there are some useless <br /> tags in the article, and I want to remove all of them without affect other contents, how to remove it? I googled and found this expression:
But, its not working! What is the right one?
Question 2:
Say, there is a <div> element in your article with specific ID and Class attribute. Within it, there are also some wrapped <div> elements, lets say 12, so the expression to find this DIV and all of its content is:
And its working! But when another article has same DIV but with different number of within elements, lets say this time, 13, when this happen, this code will not work and cause problems.
So if there is a way to exactly remove this specific DIV element (with this ID and Class) and all of its contents between it, but without affecting other parts?
Question 3:
if there is a DIV starts like this:
<div class="pic-placeholder" style="padding-bottom:66.9%;">
If we want to ONLY remove this DIV tag with specific ID or CLASS, but NOT contents between the tag,
will this code work?
Find: </?div class="pic-placeholder"(|\s+[^>]+)>
Replace: (Leave empty)
Or could you please tell me the right expression?
Thank you!
So I meet some problems when using it, please give me some tips if you know how to solve these problems! Thank you in advance!
Question 1:
Say, if there are some useless <br /> tags in the article, and I want to remove all of them without affect other contents, how to remove it? I googled and found this expression:
Code:
</?br(|\s+[^>]+)>
But, its not working! What is the right one?
Question 2:
Say, there is a <div> element in your article with specific ID and Class attribute. Within it, there are also some wrapped <div> elements, lets say 12, so the expression to find this DIV and all of its content is:
Code:
<div id="......" class="......".*?>(.*?</div>){12}
And its working! But when another article has same DIV but with different number of within elements, lets say this time, 13, when this happen, this code will not work and cause problems.
So if there is a way to exactly remove this specific DIV element (with this ID and Class) and all of its contents between it, but without affecting other parts?
Question 3:
if there is a DIV starts like this:
<div class="pic-placeholder" style="padding-bottom:66.9%;">
If we want to ONLY remove this DIV tag with specific ID or CLASS, but NOT contents between the tag,
will this code work?
Find: </?div class="pic-placeholder"(|\s+[^>]+)>
Replace: (Leave empty)
Or could you please tell me the right expression?
Thank you!