strip html from third party site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

strip html from third party site

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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]
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post 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);
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

*cough* regexps* *cough*

preg_replace as feyd already said.

Code: Select all

$rep3 = preg_replace('/<\!EDITION>(.|\s)*<\!\/EDITION>/i', '', $rep2);
Post Reply