Jump to content

Preg find / $_GET


spfoonnewb

Recommended Posts

Ok, heres what I have.. although it does not work ... I do need help with the strpos thing, to find the value. Thanks.

The current error is:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash

Strpos just returns a number.

[code]<form action="" method="POST">
<input type="text" name="url">
<input type="submit" value="Submit">
</form>

<?php

$location = $_POST["url"];
$ch = curl_init("http://$location");
$fp = fopen("test.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);

$filename = "test.txt";
$handle = fopen($filename, "r");

$read = fread($handle, filesize($filename));

$newstring = preg_match('get', $read);

echo "$newstring";

fclose($handle);

?>[/code]

Link to comment
Share on other sites

Your regular expressions have to match expressions

$newstring = preg_match('get', $read);
The pregmatch, you can't tell it to just find a word, pregmatch is for finding words that match a regular expression.

something like
preg_match("/$_GET[/i", "pathtofile/page.php") However, I am confused about this, because if you do $_GET['something'] it will literally look for something, so try and just check for $_GET[ then you know you have a match.
Link to comment
Share on other sites

You need ot define a delimiter for your regex within the preg_replace function.  Traditionally /'s are used.

[code]
<?php
$newstring = preg_match('/get/', $read);
?>
[/code]

Once you identify the urls in the text file you may find the following code useful:

[code]
<?php
$url = 'www.domain.com/index.php?foo=1&bar=2&baz=3';

print_r(getVars($url));

function getVars($url){
$tmp = explode('?', $url);
$str = $tmp[1];
$ret = array();
parse_str($str, $ret);
return $ret;
}

// Output: Array ( [foo] => 1 [bar] => 2 [baz] => 3 )
?>
[/code]

Best,

Patrick
Link to comment
Share on other sites

Hi, thanks for your time. I am still having trouble identifying the URL through the regular expressions/ preg_match. Trying through your example only returns a number "1".

Basically it is searching a text file, full of HTML code, for a string, or in this example "get".

Once it finds get, I need it to return the value of get.

So say:
[code]<html><head><title>Test</title></head><body><p>Body Content</p><p><a href="http://www.domain.com/index.php?get=test">The link</a></p></body></html>[/code]

I need php to return "test", this because get=test in the link.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.