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
https://forums.phpfreaks.com/topic/35050-preg-find-_get/#findComment-165400
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
https://forums.phpfreaks.com/topic/35050-preg-find-_get/#findComment-165402
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
https://forums.phpfreaks.com/topic/35050-preg-find-_get/#findComment-165403
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
https://forums.phpfreaks.com/topic/35050-preg-find-_get/#findComment-165414
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.