...

View Full Version : Regex



HG3
01-16-2012, 07:12 PM
please how to get XXX in text


$content = @file_get_contents("http://mysite.com/test.html");
if ($content !== false){

// GET XXX
$pattern = "/<script>setTimeout("test(XXX,' http://www.mysite.com')",66000);</script>/i";

preg_match_all($pattern, $content, $matches);
echo var_dump($matches);
}else{
echo 'ERRO';
}

BluePanther
01-16-2012, 07:14 PM
please how to get XXX in text


$content = @file_get_contents("http://mysite.com/test.html");
if ($content !== false){

// GET XXX
$pattern = "/<script>setTimeout("test(XXX,' http://www.mysite.com')",66000);</script>/i";

preg_match_all($pattern, $content, $matches);
echo var_dump($matches);
}else{
echo 'ERRO';
}

And what have you tried so far?

HG3
01-17-2012, 09:21 AM
already tried that




$content = @file_get_contents("http://mysite.com/test.html");
if ($content !== false){
$pattern = '/<script>setTimeout(\"teste(\(.*?),http:\/\/mysite.com\/test.html/)",66000/);<\/script>/i';
preg_match_all($pattern, $content, $matches);
echo var_dump($matches);

}else{
echo 'ERRO';
}

HG3
01-17-2012, 02:51 PM
? :-(

BluePanther
01-17-2012, 03:25 PM
already tried that




$content = @file_get_contents("http://mysite.com/test.html");
if ($content !== false){
$pattern = '/<script>setTimeout(\"teste(\(.*?),http:\/\/mysite.com\/test.html/)",66000/);<\/script>/i';
preg_match_all($pattern, $content, $matches);
echo var_dump($matches);

}else{
echo 'ERRO';
}



Shouldn't it be test, not teste? Are you getting any error messages from preg_match_all (check error logs)? Also, should you have www. before mysite.com?

It would make more sense to just match the setTimeout() if it's the only one that's gonna be on the page, surely? Kind of like this


$return = preg_match_all('/setTimeout\(\"test\((.*?)\,/',$content,$matches);
if($return > 0){
// matches found
var_dump($matches);
}

HG3
01-17-2012, 03:33 PM
<?php

$content = @file_get_contents("http://mysite.com/aaa.html");
if ($content !== false){
$pattern = "/<script>setTimeout(\'test(\(.*?),' http:\/\/www.mysite.com\/test.html'/)',66000/);<\/script>/i";
preg_match_all($pattern, $content, $matches);
echo var_dump($matches);

}else{
echo 'ERRO';
}

?>

ERRO:

Warning: preg_match_all() [function.preg-match-all]: Unknown modifier ')' in /home/mysite/public_html/test.php on line 6
NULL

BluePanther
01-17-2012, 03:38 PM
Edited my response above. You're not escaping the relevant parts of your regex, but you could be trying to match too much anyway. Try mine out

BluePanther
01-17-2012, 03:42 PM
I omitted the i matching option, because it doesn't look like we really need it to be case insensitive - if you do need it, you should just tack the i back onto it.

HG3
01-17-2012, 03:49 PM
ok, thank you BluePanther.
very thankful for help

BluePanther
01-17-2012, 04:06 PM
ok, thank you BluePanther.
very thankful for help

Does it work like you want it to?

HG3
01-17-2012, 04:25 PM
does it work like you want it to?
yes =)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum