Page 1 of 1
strip html from third party site
Posted: Tue Mar 08, 2005 5:54 am
by gurjit
Hi All,
I have a cfm file which is called from a third party website.
In this file there is a menu bar which i need to strip, the menu bar is in between a tag as such:
<EDITION>
<table borde="0">
<tr>
<td>my menu bar</td>
</tr>
</table>
</EDITION>
so i want to take all the code between the tag <EDITION>
Any ideas how i can strip the menu and display the remaining code from the third party website?
Posted: Tue Mar 08, 2005 7:05 am
by feyd
preg_replace() will be the fastest running, likely. I've explained how to do such a thing previously.
I hope you have permission to use their site code..
Posted: Tue Mar 08, 2005 9:05 am
by gurjit
How can i store the entire context of a html file in a variable?
for example if i have quotes("") and say:
<?php
$myvar = "
<script language="javascript">
location.href = 'point.htm';
</script>
<table border="0">
<tr>
<td></td>
</tr>
</table>
";
?>
I get an error, how can i store the entire context in a variable?
Posted: Tue Mar 08, 2005 9:08 am
by feyd
you get an error from having double quotes in a double quote string without escaping them.
file_get_contents() or a fopen()/fread()/fclose() combination will store a file into a variable.
Please use [syntax=php]tags while[/syntax][syntax=php]is offline.[/syntax]
Posted: Tue Mar 08, 2005 9:55 am
by gurjit
How can I use pre_replace() to strip all html between the tag <!EDITION> and <!/EDITION>
So if I had the following
THIS WILL DELETE
<!EDITION>
<table>
<tr>
<td>delete this whole table</td>
</tr>
<!/EDITION>
THIS WILL STAY
<table>
<tr>
<td>This will display</td>
</tr>
</table>
Posted: Tue Mar 08, 2005 10:02 am
by feyd
start using
Code: Select all
tags.
All the information you need to build your own pattern can be found from the Useful Posts thread. There's a link to it in my signature.
Posted: Tue Mar 08, 2005 11:01 am
by gurjit
I've used this code below to strip the text but when i do the substr_replace function with the star and end positions, it strips the actual text and not the html tags....any ideas how i can make sure all the html in the string is stripped and tags in the start and end positions?
Code: Select all
$spos = strpos($rep2,"<!EDITION>");
$epos = strpos($rep2,"<!/EDITION>");
$rep3 = substr_replace($rep2, "", $spos, $epos);
Posted: Tue Mar 08, 2005 11:17 am
by Chris Corbyn
*cough* regexps* *cough*
preg_replace as feyd already said.
Code: Select all
$rep3 = preg_replace('/<\!EDITION>(.|\s)*<\!\/EDITION>/i', '', $rep2);