Problem with post url in script

Hello,

I have problem with one script.

Script has been static and i need change that for dynamic

Idea : http:www.blablabla.com/script.php?http://test.com/ - need put in the script dynamic http://test.com/

Here is script :

[php]<?php

$url = $_SERVER[‘REQUEST_URI’];
if(isset($_GET[“sub”]))

$page = fopen($url, ‘r’);
$content = “”;
while( !feof( $page ) ) {
$buffer = trim( fgets( $page, 4096 ) );
$content .= $buffer;
}

$start = “

”;
$end = “</p>”;

preg_match( “/$start(.*)$end/s”, $content, $match);
$mytext = $match[1];
echo “$mytext”;
?>[/php]

Thanks in advance

Hi Lacho,

I would be happy to try to help you, but I am having trouble understanding what it is you are looking to do.

There are some problems with the code you posted. Can you tell me if this script actually works for you?

It looks like you are attempting to get all the content that is between the first html paragraph element and the last paragraph element on a page that is provided in the url.

In order to pass an address in the url as your idea indicates, you will need to give it a name that can be used in your script. Example: http:www.blablabla.com/script.php?myUrl=http://test.com/

In your script, you can access the value that was passed for myUrl as follows:[php]$value = $_GET[‘myUrl’];[/php]
Will the url that you are going to be passing to the script always be on your server?

Do you want to capture everything between the first html paragraph opening tag and the last html paragraph closing tag at the myUrl address into a single variable or just the first paragraph that is encountered?

Right now, your script will look in the url for either “?sub” or “&sub” depending on where it is placed. If it finds this, it will execute the line[php]$page = fopen($url, ‘r’);[/php]This is the only line that will be dependent on the “sub” condition. All the rest of the code will run regardless. I am certain that this is not what you want. You need to add a bracket { after your if…[php]if(isset($_GET[“sub”])) {[/php]…and a closing bracket } at the end of the section that will be dependent on the if statement (in this case, probably right before your php close tag “?>”

You are currently using fopen to try to retrieve the page. If the pages will not be on your server, or your server is not configured appropriately for this, fopen will fail. Many servers forbid fopen from a remote url. You might want to consider using curl instead.

Using regex may be appropriate for what you are looking to do, but depending on your needs, you may be better off with another method. We will address this as we know more, but for now, I am assuming this will work.

Sponsor our Newsletter | Privacy Policy | Terms of Service