-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace-html-elements.php
More file actions
29 lines (24 loc) · 952 Bytes
/
replace-html-elements.php
File metadata and controls
29 lines (24 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/** Let\'s suppose $content contains the entire HTML or a part of the HTML
* from which we need to replace/remove specific parts
*/
// Remove the element which has the element2 ID
$content = preg_replace(
'#<div[^>]*id="element2"[^>]*>.*?</div>#is', '', $content
);
// Remove the element which has the yasglobal-translation ID
$content = preg_replace(
'#<table[^>]*id="yasglobal-translation"[^>]*>.*?</table>#is', '', $content
);
// Remove the elements which have the wrapper class
$content = preg_replace(
'#<table[^>]*class="wrapper"[^>]*>.*?</table>#is', '', $content
);
// Replace the element which has the element2 ID
$content = preg_replace(
'#<div[^>]*id="element2"[^>]*>.*?</div>#is', '<div>Testing Element</div>', $content
);
// Replace the element which has the yasglobal-translation ID
$content = preg_replace(
'#<table[^>]*id="yasglobal-translation"[^>]*>.*?</table>#is', '<div>Testing Element</div>', $content
);