/    Sign up×
Community /Pin to ProfileBookmark

How can I parse and show a page?

I want to remove specific parts of code and show this.

How do I do this?

I’ve written some code to do the parsing (with help in another thread I posted here) and get rid of the bits I don’t want to show.

So far, I have the code:

[code=php] $wholePage = preg_replace(“/<!–s*Admin Code Starts*–>.*?<!–s*Admin Code Ends*–>/is”, “”, $wholePage);[/code]

This will get rid of the parts I don’t want to show.

But… how then do I display the parsed page?

Thanks.

OM

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@OM2authorMay 29.2008 — any one? ?
Copy linkTweet thisAlerts:
@jacjil2May 29.2008 — echo $wholepage;
Copy linkTweet thisAlerts:
@OM2authorMay 29.2008 — thanks for the reply.

i need to write another php file that loads a php file, but parses out some unwated text and shows the web page without the bit i dont want to show.

does that make sense?

thanks.
Copy linkTweet thisAlerts:
@jacjil2May 30.2008 — Idk. Can you file_put_contents a .php file or is that function just for .txt files and stuff?

I'm a newb myself with php, but they say the student teaches the teacher.
Copy linkTweet thisAlerts:
@OM2authorMay 30.2008 — Idk. Can you file_put_contents a .php file or is that function just for .txt files and stuff?

I'm a newb myself with php, but they say the student teaches the teacher.[/quote]


hmm... i dont quite understand what u say. ?

i'm pulling my hair out over this one.

i thought doing something like this would be easy and staright forward: read the contents of a webpage and dsiplay it but parse out what u dont want.

? ?

i'd never done it before: but i kind of thought this was a standard feature available to backend languages?
Copy linkTweet thisAlerts:
@OM2authorMay 30.2008 — i don't seem to be getting anywhere with this question. ?

let me show by example what i want.

let's say i have the following cod ein my html file:[CODE]<html><head><title></title></head>
<body>
Hello 123
<!-- DONT SHOW START -->
Spiderman
<!-- DONT SHOW END -->
</body>
</html>
[/CODE]


i want to be able to show this same page except when i don't want to show anything between [CODE]<!-- DONT SHOW START -->[/CODE] and [CODE]<!-- DONT SHOW END -->[/CODE]

i may have confused things the way i explained what i wanted.

surely doing this HAS to be very simple? ?
Copy linkTweet thisAlerts:
@andre4s_yMay 31.2008 — So far i understand your problem :

1. You need to read the contents of a webpage, right?

You can use function such as : fopen() or file_get_contents() or using CURL functions. For example using file_get_contents("your_webpage.html") and place the output to the variable $wholePage(your first post).

2. Then eliminate your unwanted code.
[code=php]
$wholePage = preg_replace("/&lt;!--s*Admin Code Starts*--&gt;.*?&lt;!--s*Admin Code Ends*--&gt;/is", "", $wholePage);
[/code]

Consider your code for replacing is correct.

3. Output it. Nah, how do you want to output it? Display it in the same page??

If that so, you can just echo $wholePage, with or without htmlentities() function.

If you want to output it to file, you can use file_put_contents("your_webpage.html") function. When people access your webpage, it will display the code without your unwanted code.

Thats all..

Or i miss something else??
Copy linkTweet thisAlerts:
@jacjil2May 31.2008 — He wants to return php. Curl would just return the output.

If you could and I'm not sure if possible:

[COLOR="Red"]put_file_contents("newpage.php",$wholepage);

header("Location: newpage.php");

[/COLOR]


I'm a newb so I'm probably hard to understand.
Copy linkTweet thisAlerts:
@OM2authorMay 31.2008 — i kinda got the answer from somewhere else.

this is what i want:

[COLOR=#000000][COLOR=#0000BB]<?php

$page [/COLOR]
[COLOR=#007700]= [/COLOR][COLOR=#0000BB]file_get_contents[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'myfile.html'[/COLOR][COLOR=#007700]);

[/COLOR]
[COLOR=#0000BB]$page [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]preg_replace[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'|<!-- DONT SHOW START -->.*?<!-- DONT SHOW END -->|is'[/COLOR][COLOR=#007700],[/COLOR][COLOR=#DD0000]''[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$page[/COLOR][COLOR=#007700]);

echo [/COLOR]
[COLOR=#0000BB]$page[/COLOR][COLOR=#007700];

[/COLOR]
[COLOR=#0000BB]?>[/COLOR][/COLOR]


thanks for the replies.
Copy linkTweet thisAlerts:
@andre4s_yJun 01.2008 — Ow.. just like that?? ?

Warning : in regex, you must escape !, < and >. So the pattern is :

|<!-- DONT SHOW START -->.*?<!-- DONT SHOW END -->|is
[/quote]
Copy linkTweet thisAlerts:
@OM2authorJun 01.2008 — hey... thanks for that. ?

i'll add it to the code.
Copy linkTweet thisAlerts:
@jacjil2Jun 03.2008 — echo $wholepage;[/QUOTE]
SO basically it was this ^ lol
×

Success!

Help @OM2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...